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

Embedded records mixin should use the correct serialization key when deserialize configuration is set, Fixes #2556 #2790

Merged

Conversation

agrobbin
Copy link
Contributor

This is my first attempted contribution to Ember Data, so if I'm approaching anything the wrong way, please let me know!

When extending the DS.EmbeddedRecordsMixin, if you configure a belongsTo relationship as { serialize: 'id', deserialize: 'records' }, it won't actually pay attention to the serialize: 'id' option, but use the deserialize: 'records' option. This is because of serializeBelongsTo and the reimplementation of keyForRelationship, which notices the deserialize option instead of the serialize option.

Fixes #2556.

@joeruello
Copy link

Hit this today, thanks for the fix!

@bmac bmac added this to the 1.0.0-beta.16 milestone Feb 28, 2015
keyForRelationship: function(key, type) {
if (this.hasDeserializeRecordsOption(key)) {
keyForRelationship: function(key, type, method) {
if (method === undefined) { method = 'deserialize'; }
Copy link
Member

Choose a reason for hiding this comment

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

I think the convention is to put the conditional body on its own line so its easier to inset a breakpoint if needed,

@bmac
Copy link
Member

bmac commented Mar 1, 2015

For symmetry, I'd like to see the 'deserialize' argument included on the keyForRelationship relationship call at line https://github.com/agrobbin/ember-data/blob/2556-embedded-records-mixin-serialize-ids/packages/ember-data/lib/serializers/embedded_records_mixin.js#L340

@bmac
Copy link
Member

bmac commented Mar 1, 2015

@pixelhandler and @igorT would one of you like to review this pr since you have more familiarity with the EmbeddedMixin and (presumably) with ActiveRecord?

@pixelhandler
Copy link
Contributor

@bmac I can take a look in the next day or two

@agrobbin agrobbin force-pushed the 2556-embedded-records-mixin-serialize-ids branch 2 times, most recently from 2b13553 to 5644d84 Compare March 1, 2015 23:42
@agrobbin
Copy link
Contributor Author

agrobbin commented Mar 1, 2015

@bmac done and done!

keyForRelationship: function(key, type) {
if (this.hasDeserializeRecordsOption(key)) {
keyForRelationship: function(key, type, method) {
if (method === undefined) {
Copy link
Member

Choose a reason for hiding this comment

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

This isn't needed anymore right?

@igorT
Copy link
Member

igorT commented Mar 11, 2015

Thanks for the PR! Looks pretty good. If we are gonna add 'serialize'/'deserialize', could you do it throughout all the serializers and not just the EmbeddedRecords one?

@agrobbin
Copy link
Contributor Author

@igorT I can certainly do that, but won't that cause jsHint warnings about unused arguments in the keyForRelationship function definitions when it happens to not be used?

@agrobbin agrobbin force-pushed the 2556-embedded-records-mixin-serialize-ids branch from 5644d84 to 319acc3 Compare March 11, 2015 23:35
@agrobbin
Copy link
Contributor Author

@igorT or were you thinking of just adding the argument to the call-sites and since we only happen to use it in the EmbeddedRecordsMixin mixin, leave the other keyForRelationship definitions alone?

@agrobbin agrobbin force-pushed the 2556-embedded-records-mixin-serialize-ids branch from 319acc3 to f8902bd Compare March 11, 2015 23:48
@agrobbin
Copy link
Contributor Author

@igorT I went with the latter. Let me know if I can do anything else!

@agrobbin agrobbin force-pushed the 2556-embedded-records-mixin-serialize-ids branch from f8902bd to 1bbf895 Compare March 18, 2015 20:49
@agrobbin
Copy link
Contributor Author

@igorT is there anything remaining to get this in before beta 16 goes out?

@bmac bmac removed this from the 1.0.0-beta.16 milestone Mar 22, 2015
@bmac bmac removed the team-review label Apr 3, 2015
@bmac
Copy link
Member

bmac commented Apr 3, 2015

@agrobbin This issue was discussed in the last Ember Data meeting and it was decided that if this change is made for keyForRelationship the method param should also be passed into keyForAttribute as well.

@agrobbin agrobbin force-pushed the 2556-embedded-records-mixin-serialize-ids branch from 1bbf895 to c819aa8 Compare April 4, 2015 04:14
@agrobbin
Copy link
Contributor Author

agrobbin commented Apr 4, 2015

@bmac 👍 just pushed up a second commit to this branch, happy to squash them into 1 assuming you like how this looks!

@pixelhandler
Copy link
Contributor

Seems good 👍

To support getting the right key, it seems necessary to know whether the key will be used to serialize or deserialize, nice.

…deserialize configuration is set

When extending the `DS.EmbeddedRecordsMixin`, if you configure a relationship as `{ serialize: 'id', deserialize: 'records' }`, it won't actually pay attention to the `serialize: 'id'` option, but use the `deserialize: 'records'` option.
@agrobbin agrobbin force-pushed the 2556-embedded-records-mixin-serialize-ids branch from c819aa8 to 5bfda83 Compare April 4, 2015 20:02
@agrobbin
Copy link
Contributor Author

agrobbin commented Apr 4, 2015

Squashed!

igorT added a commit that referenced this pull request Apr 13, 2015
…rialize-ids

Embedded records mixin should use the correct serialization key when deserialize configuration is set, Fixes #2556
@igorT igorT merged commit dcaf77b into emberjs:master Apr 13, 2015
@igorT
Copy link
Member

igorT commented Apr 13, 2015

Thank you @agrobbin

@agrobbin
Copy link
Contributor Author

No problem!

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.

EmbeddedRecordsMixin issue with belongsTo deserialize: 'records' + serialize: 'id'
5 participants