mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
When using embed: :ids ; embed_in_root: true, and serializing multiple objects,
only the associated objects of the last object in the collection will actually show up in the serialized data. For example, if you serialize a collection of two posts, each containing one or more comments, only the comments of the last post show up. The reason is a Hash#merge wich overwrites the array rather than appending to it. This commit fixes this by merging the collection arrays, rather than the top-level hashes.
This commit is contained in:
2
test/fixtures/poro.rb
vendored
2
test/fixtures/poro.rb
vendored
@@ -26,6 +26,8 @@ class Profile < Model
|
||||
end
|
||||
|
||||
class Post < Model
|
||||
attr_writer :comments
|
||||
|
||||
def comments
|
||||
@comments ||= [Comment.new(content: 'C1'),
|
||||
Comment.new(content: 'C2')]
|
||||
|
||||
Reference in New Issue
Block a user