mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Cleanup
This commit is contained in:
parent
ee69293c8f
commit
7d8fb1606b
@ -341,7 +341,8 @@ module ActiveModel
|
|||||||
next if reflection.excluded?(self)
|
next if reflection.excluded?(self)
|
||||||
next unless include_directive.key?(key)
|
next unless include_directive.key?(key)
|
||||||
|
|
||||||
y.yield reflection.build_association(self, instance_options, include_slice)
|
association = reflection.build_association(self, instance_options, include_slice)
|
||||||
|
y.yield association
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -390,14 +391,12 @@ module ActiveModel
|
|||||||
|
|
||||||
# @api private
|
# @api private
|
||||||
def associations_hash(adapter_options, options, adapter_instance)
|
def associations_hash(adapter_options, options, adapter_instance)
|
||||||
relationships = {}
|
|
||||||
include_directive = options.fetch(:include_directive)
|
include_directive = options.fetch(:include_directive)
|
||||||
associations(include_directive).each do |association|
|
include_slice = options[:include_slice]
|
||||||
adapter_opts = adapter_options.merge(include_directive: include_directive[association.key])
|
associations(include_directive, include_slice).each_with_object({}) do |association, relationships|
|
||||||
relationships[association.key] ||= association.serializable_hash(adapter_opts, adapter_instance)
|
adapter_opts = adapter_options.merge(include_directive: include_directive[association.key], adapter_instance: adapter_instance)
|
||||||
|
relationships[association.key] = association.serializable_hash(adapter_opts, adapter_instance)
|
||||||
end
|
end
|
||||||
|
|
||||||
relationships
|
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|||||||
@ -37,13 +37,13 @@ module ActiveModel
|
|||||||
# 1) as 'comments' and named 'comments'.
|
# 1) as 'comments' and named 'comments'.
|
||||||
# 2) as 'object.comments.last(1)' and named 'last_comments'.
|
# 2) as 'object.comments.last(1)' and named 'last_comments'.
|
||||||
#
|
#
|
||||||
# PostSerializer._reflections #=>
|
# PostSerializer._reflections # =>
|
||||||
# # [
|
# # {
|
||||||
# # HasOneReflection.new(:author, serializer: AuthorSerializer),
|
# # author: HasOneReflection.new(:author, serializer: AuthorSerializer),
|
||||||
# # HasManyReflection.new(:comments)
|
# # comments: HasManyReflection.new(:comments)
|
||||||
# # HasManyReflection.new(:comments, { key: :last_comments }, #<Block>)
|
# # last_comments: HasManyReflection.new(:comments, { key: :last_comments }, #<Block>)
|
||||||
# # HasManyReflection.new(:secret_meta_data, { if: :is_admin? })
|
# # secret_meta_data: HasManyReflection.new(:secret_meta_data, { if: :is_admin? })
|
||||||
# # ]
|
# # }
|
||||||
#
|
#
|
||||||
# So you can inspect reflections in your Adapters.
|
# So you can inspect reflections in your Adapters.
|
||||||
class Reflection < Field
|
class Reflection < Field
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user