-
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
Fix root/meta for ArraySerializer #915
Conversation
I've rebased this on master and squashed in a commit to make both calls to |
def root=(root) | ||
@objects.first.root = root if @objects.first | ||
if root == true && @objects.first | ||
@objects.first.class.root_name |
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.
I'm not sure about using the root_name
here. ArraySerializer is pretty abstract, take a lott at this piece of code for example:
@objects = objects.map do |object|
serializer_class = options.fetch(
:serializer,
ActiveModel::Serializer.serializer_for(object)
)
serializer_class.new(object, options.except(:serializer))
end
By checking this code we can presume that the objects might not be instances from the same class. Wrap them by the class name from its first object doesn't would be right.
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.
The problem here is the jsonapi adapter. It sets serializer.root = true
in its initializer. I'm not sure how to deal with heterogenous arrays.
When all of the elements are the same, it makes sense to autodetect the json_key
from the first element. When they're not the same, there's not a default that makes sense so we'd need to require a string/symbol to be passed in as the root. How do we handle the case where the root is true
but we have a heterogenous array?
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.
We could define a default data
root by default is there isn't one defined. But I'm not convinced yet about the root implementation on ArraySerializer
😝
I'm going to retire this PR. We ended up ditching both jsonapi and AMS 0.10.x in favor of 0.8.3 for now. More of a 'just works' approach. |
😢 |
@joaomdmoura This is fixed in #936, no? |
@bf4 I haven't tested it, so I'm not sure about it. But supposedly yes. |
No description provided.