embed_in_root works even if serializer is invoked through another serializers' association which itself does not have embed_in_root set

This commit is contained in:
Radan Skoric
2014-08-23 18:21:24 +02:00
parent 2fec5111ef
commit ddfd8d2c11
4 changed files with 59 additions and 2 deletions

View File

@@ -194,12 +194,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