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

Add method argument to key serialization docs #3035

Merged
merged 1 commit into from
May 1, 2015

Conversation

Dremora
Copy link
Contributor

@Dremora Dremora commented Apr 30, 2015

In JSONSerializer, both keyForAttribute and keyForRelationship get an extra undocumented parameter, method (which can be either serialize or deserialize). This PR adds the missing bits.
Also there was a call to keyForAttribute with a method argument missing — 'serialize` is now explicitly being passed there.

return Ember.String.underscore(attr).toUpperCase();
} else {
return Ember.String.camelize(attr.toLowerCase());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets leave this example as it was (although feel free to add the method parameter to the function declaration). The new implementation doesn't match the text above it.

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 original example would work fine if the data is never saved back to the server. If it is, though, we do need to perform the reverse conversion. Perhaps I should instead expand the text above and and a bit clarifying this reverse procedure?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The keyForAttribute method's attr parameter is always the name of the attribute as defined on the Model. So if the API you are working with consistently uses the same keys when serializing and deserializing then you should not need to include a check on the method argument.

Using method method is usually reserved for the rare case where an API returns data using one key, but then expects it to be listed under a different key when updating.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense now, thanks! I'll update the PR.

bmac added a commit that referenced this pull request May 1, 2015
Add method argument to key serialization docs
@bmac bmac merged commit 8c81d41 into emberjs:master May 1, 2015
@bmac
Copy link
Member

bmac commented May 1, 2015

Thanks!

@Dremora Dremora deleted the key_serializer_docs branch May 3, 2015 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants