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:
Alexandre de Oliveira
2014-11-11 14:35:00 -02:00
parent 33e8d09ad0
commit 971f501e55
6 changed files with 59 additions and 5 deletions

View File

@@ -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