diff --git a/lib/active_model/array_serializer.rb b/lib/active_model/array_serializer.rb index 5ab4cdb2..1fce09e3 100644 --- a/lib/active_model/array_serializer.rb +++ b/lib/active_model/array_serializer.rb @@ -45,8 +45,11 @@ module ActiveModel def embedded_in_root_associations @object.each_with_object({}) do |item, hash| serializer_for(item).embedded_in_root_associations.each_pair do |type, objects| - hash[type] = hash.fetch(type, []).concat(objects) - hash[type].uniq! + if hash.has_key?(type) + hash[type].concat(objects).uniq! + else + hash[type] = objects + end end end end