From a862929f811aeb3e3a7f7aa87e2ce392da0e3f68 Mon Sep 17 00:00:00 2001 From: Gauthier Delacroix Date: Tue, 9 Sep 2014 11:27:08 +0200 Subject: [PATCH] Fix embed_in_root_key merging --- lib/active_model/array_serializer.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/active_model/array_serializer.rb b/lib/active_model/array_serializer.rb index e0c3ecfc..aabfb651 100644 --- a/lib/active_model/array_serializer.rb +++ b/lib/active_model/array_serializer.rb @@ -51,7 +51,11 @@ module ActiveModel next if !objects || objects.flatten.empty? if hash.has_key?(type) - hash[type].concat(objects).uniq! + case hash[type] when Hash + hash[type].deep_merge!(objects){ |key, old, new| (Array(old) + Array(new)).uniq } + else + hash[type].concat(objects).uniq! + end else hash[type] = objects end