mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Bugfix: include nested has_many association
Currently, doing `include: author.bio` would work correctly, but not for has_many associations such as `include: author.roles`. This fixes it. The problem was basically that we were not handling arrays for has_many linked, as happens for ArraySerializers.
This commit is contained in:
@@ -8,6 +8,7 @@ module ActiveModel
|
||||
def setup
|
||||
@author = Author.new(name: 'Steve K.')
|
||||
@author.bio = nil
|
||||
@author.roles = nil
|
||||
@first_post = Post.new(id: 1, title: 'Hello!!', body: 'Hello, world!!')
|
||||
@second_post = Post.new(id: 2, title: 'New Post', body: 'Body')
|
||||
@author.posts = [@first_post, @second_post]
|
||||
|
||||
@@ -16,6 +16,7 @@ module ActiveModel
|
||||
@second_post.author = @author
|
||||
@author.posts = [@first_post, @second_post]
|
||||
@author.bio = @bio
|
||||
@author.roles = []
|
||||
@bio.author = @author
|
||||
|
||||
@serializer = ArraySerializer.new([@first_post, @second_post])
|
||||
|
||||
Reference in New Issue
Block a user