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:
Steve Klabnik
2014-08-31 19:57:27 -04:00
4 changed files with 59 additions and 2 deletions

View File

@@ -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