mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +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
test/fixtures/poro.rb
vendored
8
test/fixtures/poro.rb
vendored
@@ -40,6 +40,7 @@ Comment = Class.new(Model)
|
||||
Author = Class.new(Model)
|
||||
Bio = Class.new(Model)
|
||||
Blog = Class.new(Model)
|
||||
Role = Class.new(Model)
|
||||
|
||||
PostSerializer = Class.new(ActiveModel::Serializer) do
|
||||
attributes :title, :body, :id
|
||||
@@ -60,9 +61,16 @@ AuthorSerializer = Class.new(ActiveModel::Serializer) do
|
||||
attributes :id, :name
|
||||
|
||||
has_many :posts, embed: :ids
|
||||
has_many :roles, embed: :ids
|
||||
belongs_to :bio
|
||||
end
|
||||
|
||||
RoleSerializer = Class.new(ActiveModel::Serializer) do
|
||||
attributes :id, :name
|
||||
|
||||
belongs_to :author
|
||||
end
|
||||
|
||||
BioSerializer = Class.new(ActiveModel::Serializer) do
|
||||
attributes :id, :content
|
||||
|
||||
|
||||
Reference in New Issue
Block a user