-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include does not work on nested associations #1194
Comments
It no longer is implemented on serializer association definitions. This was |
As @NullVoxPopuli said, this feature is currently not part of master (only the adapter option). Could you provide a link to the doc where it says otherwise so that we correct it? |
I was reading on #1127. It's not a doc, sorry. I understand the point that you said but this logic on controller is not against DRY? I'll need to set include on every controller that I use the serializer. If this logic was on serializer I didn't repeat on every controller. |
@givigier Currently, we're thinking about going down the way described in #1193. Basically, what it allows, in your case, is: class V1::QuoteSerializer < ActiveModel::Serializer
attributes :id
has_one :company do
attributes :id
has_many :phones do
attributes :number
end
has_many :addresses do
attributes :city
end
end
end Combined with |
Thanks for pointing out the inconsistent PR description though, I'm fixing this right now. |
Thanks! I guess we could close this issue. |
I'm trying to use the feature of nested associations. My structure of serializers is:
When I add 'include' of associations on controller(like on QuotesController) it works fine and return:
{"id"=>"1", "company"=>{"id"=>"1", "addresses"=>[], "phones"=>[]}}
Otherwise, when I add 'include' of associations on serializer it does not work and doesn't return addresses and phones.
{"id"=>"1", "company"=>{"id"=>"1"}}
I was reading the docs and apparently it should work on serializer too.
The text was updated successfully, but these errors were encountered: