mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Merge pull request #601 from radanskoric/fix-nested-embed-in-root
Fix for nested embed_in_root when serializer used as part of an association
This commit is contained in:
@@ -195,12 +195,15 @@ end
|
||||
included_associations = filter(associations.keys)
|
||||
associations.each_with_object({}) do |(name, association), hash|
|
||||
if included_associations.include? name
|
||||
association_serializer = build_serializer(association)
|
||||
# we must do this always because even if the current association is not
|
||||
# embeded in root, it might have its own associations that are embeded in root
|
||||
hash.merge!(association_serializer.embedded_in_root_associations) {|key, oldval, newval| [newval, oldval].flatten }
|
||||
|
||||
if association.embed_in_root?
|
||||
if association.embed_in_root_key?
|
||||
hash = hash[association.embed_in_root_key] ||= {}
|
||||
end
|
||||
association_serializer = build_serializer(association)
|
||||
hash.merge!(association_serializer.embedded_in_root_associations) {|key, oldval, newval| [newval, oldval].flatten }
|
||||
|
||||
serialized_data = association_serializer.serializable_object
|
||||
key = association.root_key
|
||||
|
||||
Reference in New Issue
Block a user