mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56:50 +00:00
Fixes #1211 - retrieve the key from the reflection options when building associations
This commit is contained in:
parent
1f08865a10
commit
f8323fc9e5
@ -19,6 +19,7 @@ Features:
|
|||||||
associations for JSON and Attributes adapters via the `include` option (@NullVoxPopuli, @beauby).
|
associations for JSON and Attributes adapters via the `include` option (@NullVoxPopuli, @beauby).
|
||||||
|
|
||||||
Fixes:
|
Fixes:
|
||||||
|
- [#1214](https://github.com/rails-api/active_model_serializers/pull/1214) retrieve the key from the reflection options when building associations (@NullVoxPopuli, @hut8)
|
||||||
|
|
||||||
Misc:
|
Misc:
|
||||||
- [#1178](https://github.com/rails-api/active_model_serializers/pull/1178) env CAPTURE_STDERR=false lets devs see hard failures (@bf4)
|
- [#1178](https://github.com/rails-api/active_model_serializers/pull/1178) env CAPTURE_STDERR=false lets devs see hard failures (@bf4)
|
||||||
|
|||||||
@ -92,7 +92,8 @@ module ActiveModel
|
|||||||
|
|
||||||
Enumerator.new do |y|
|
Enumerator.new do |y|
|
||||||
self.class._reflections.each do |reflection|
|
self.class._reflections.each do |reflection|
|
||||||
next unless include_tree.key?(reflection.name)
|
key = reflection.options.fetch(:key, reflection.name)
|
||||||
|
next unless include_tree.key?(key)
|
||||||
y.yield reflection.build_association(self, instance_options)
|
y.yield reflection.build_association(self, instance_options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -46,6 +46,11 @@ module ActionController
|
|||||||
render json: @post, include: [:author], adapter: :json_api
|
render json: @post, include: [:author], adapter: :json_api
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def render_resource_with_include_of_custom_key_by_original
|
||||||
|
setup_post
|
||||||
|
render json: @post, include: [:reviews], adapter: :json_api, serializer: PostWithCustomKeysSerializer
|
||||||
|
end
|
||||||
|
|
||||||
def render_resource_with_nested_include
|
def render_resource_with_nested_include
|
||||||
setup_post
|
setup_post
|
||||||
render json: @post, include: [comments: [:author]], adapter: :json_api
|
render json: @post, include: [comments: [:author]], adapter: :json_api
|
||||||
@ -137,6 +142,18 @@ module ActionController
|
|||||||
assert_equal expected_linked, response['included']
|
assert_equal expected_linked, response['included']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_render_resource_with_include_of_custom_key_by_original
|
||||||
|
get :render_resource_with_include_of_custom_key_by_original
|
||||||
|
response = JSON.parse(@response.body)
|
||||||
|
assert response.key? 'included'
|
||||||
|
|
||||||
|
relationships = response['data']['relationships']
|
||||||
|
|
||||||
|
assert_includes relationships, 'reviews'
|
||||||
|
assert_includes relationships, 'writer'
|
||||||
|
assert_includes relationships, 'site'
|
||||||
|
end
|
||||||
|
|
||||||
def test_render_resource_with_nested_include
|
def test_render_resource_with_nested_include
|
||||||
get :render_resource_with_nested_include
|
get :render_resource_with_nested_include
|
||||||
response = JSON.parse(@response.body)
|
response = JSON.parse(@response.body)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user