Closed
Description
Hi, I've tried to move my project from 0-9-3 to 0-10-0 and found that version 0.10 doesn't support nested associations.
class AppSerializer < ActiveModel::Serializer
has_one :user, serializer: UserSerializer
end
class UserSerializer < ActiveModel::Serializer
has_one :address, serializer: AddressSerializer
has_one :account, serializer: AccountSerializer
has_many :devices
attributes :id, :login
end
In my controller i have
render json: @app
and the response is
{ user: {id: 1, login: "smb@email.com} }
Cause json adapter, takes into consideration only attributes of association, but not nested associations of user.
serializer.each_association do |name, association, opts|
if association.respond_to?(:each)
array_serializer = association
@hash[name] = array_serializer.map do |item|
cache_check(item) do
item.attributes(opts)
end
end
else
if association && association.object
@hash[name] = cache_check(association) do
association.attributes(options)
end
elsif opts[:virtual_value]
@hash[name] = opts[:virtual_value]
else
@hash[name] = nil
end
end
end