-
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
added option to include nested associations #952
Conversation
Great @iMacTia! I was really looking forward to implement it! |
Added some basic tests, unfortunately was my first time with Minitest, I found myself a bit disoriented @_@ |
def test_no_option_is_passed_in | ||
@post_serializer = PostSerializerWithNestedAssociations.new(@post) | ||
json = ActiveModel::Serializer::Adapter::Json.new(@post_serializer).as_json | ||
assert json[:author][:bio] != nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iMacTia could you just assert the content itself? So we also validate that is matches the expected one 😄
expected_return = {
...
}
assert_equal json[:author][:bio] , expected_return
item.attributes(opts) | ||
opts[:include_nested_associations] ? | ||
self.class.new(item).serializable_hash : | ||
item.attributes(opts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be a good time to extract add_association
to its own method, like the json_api adapter has
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@iMacTia need any help bringing this to completion? I'm happy to pair |
I thought you guys were working on it (extracting |
Yeap @iMacTia, indeed I'm inclined to merge the Associations Refactoring, but I still think that nested associations are a need, we would still be willing to merge it. Maybe on top or the associations refactoring after I merge it. |
Hi @joaomdmoura, just wanted to know what's the plan for this feature, are you still waiting for something from me? We've been using my branch in production for some months now, seems working with no problems. I see a similar problem has been addressed for side-loading, but looks to me like a different feature after all |
Hi what is the status here. I would also like to see the possibilty of deep nesting associations, as I´m converting from jbuilder to AMS right now... |
Hi @casiodk, Just asked the same yesterday :) |
Yes it seems like the best choice, but not as flexible |
Hey @iMacTia and @casiodk, first of all thank you for the support and interest on this. 😄 Some ppl have being addressing this with different approaches, I think this PR is pretty outdated right now, and I liked the discussion on #1113, and reviewed #1114. I totally agree with your comment on #1113
This might be a real need for some ppl, @NullVoxPopuli even proposed a solution for that here. Let's go for nested association and see if more ppl back up the |
Devs can now use a new parameter in Serializer classes when defining associations (has_many, has_one, ...):
include_nested_assosiations
.If this option is true, serialization will "follow" the association including not only its attributes, but also its associations.