Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

ryansch
Copy link
Contributor

@ryansch ryansch commented May 19, 2015

No description provided.

@ryansch
Copy link
Contributor Author

ryansch commented May 21, 2015

I've rebased this on master and squashed in a commit to make both calls to #assert_equal use the correct argument order.

def root=(root)
@objects.first.root = root if @objects.first
if root == true && @objects.first
@objects.first.class.root_name
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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 😝

@ryansch
Copy link
Contributor Author

ryansch commented Jun 8, 2015

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.

@ryansch ryansch closed this Jun 8, 2015
@ryansch ryansch deleted the array-meta branch June 8, 2015 22:12
@joaomdmoura
Copy link
Member

😢

@bf4
Copy link
Member

bf4 commented Jun 11, 2015

@joaomdmoura This is fixed in #936, no?

@joaomdmoura
Copy link
Member

@bf4 I haven't tested it, so I'm not sure about it. But supposedly yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants