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

[BUGFIX release] fix regression where dynamically set id is not serialized in a create… #3701

Merged
merged 1 commit into from
Sep 8, 2015

Conversation

acburdine
Copy link
Contributor

… save request

closes #3694

  • converts the 'id' property to a computed property alias of internalmodel.id

@acburdine acburdine changed the title fix regression where dynamically set id is not serialized in a create… [BUGFIX release] fix regression where dynamically set id is not serialized in a create… Aug 26, 2015
@@ -295,7 +295,7 @@ var Model = Ember.Object.extend(Ember.Evented, {
@property id
@type {String}
*/
id: null,
id: Ember.computed.alias('_internalModel.id'),
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 worried about this being a breaking changed. It is possible to access a record's id without using a getter (record.id). Maybe we want to use an ES5 getter to grab the id out of the internal model?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would that work for setting the id as well? The main cause of the regression is that the internalModel id is not being set correctly when it is modified after creation.

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 it would work for setting the id as well if we also implemented an ES5 property setter.

@wecc
Copy link
Contributor

wecc commented Aug 26, 2015

Won't this mess up the typeMaps in store? I know there are issues related to this and it would be great to get it fixed, just want to make sure we're solving it in a reliable way.

Ping @igorT for review.

@bmac
Copy link
Member

bmac commented Aug 27, 2015

@wecc I believe the store already has code to update the typeMaps after the createRecord record request is resolved. @acburdine's usecase of setting the id of a new record on the client side use to work before Ember Data beta.19.

@acburdine
Copy link
Contributor Author

@bmac Anything else I need to do for this or is it just waiting on review?

@@ -541,9 +540,8 @@ InternalModel.prototype = {
},

setId: function(id) {
Ember.assert('Object is a newly created model instance', this.isNew);
Copy link
Member

Choose a reason for hiding this comment

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

isNew is a function. Ember.assert('Object is a newly created model instance', this.isNew());

Copy link
Member

Choose a reason for hiding this comment

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

Also lets make the assertion message say something like "A record's id can not be chanced once it is in the loaded state."

@acburdine acburdine force-pushed the id-fic branch 2 times, most recently from 8c99b0b to 385224e Compare August 29, 2015 04:48
@@ -541,9 +540,8 @@ InternalModel.prototype = {
},

setId: function(id) {
Ember.assert('A record\'s id cannot be changed once it is in the loaded state', this.isNew());
Copy link
Member

Choose a reason for hiding this comment

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

Looks like there are a few code paths that try to set a record with an id to the same id. Changing the assertion logic to the following should work.

var oldId = this.id;
Ember.assert('A record\'s id cannot be changed once it is in the loaded state', oldId === null || id === oldId || this.isNew());

return this._internalModel.id;
}
}
})
Copy link
Member

Choose a reason for hiding this comment

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

jshint wants a semicolon here.

@bmac
Copy link
Member

bmac commented Sep 6, 2015

@acburdine Looks like these changes have caused this test to fail.

I think the simplest fix would be to add this assertion to the end of the model's willMergeMixin method.

Ember.assert("You may not set `id` as an attribute on your model. Please remove any lines that look like: `id: DS.attr('<type>')` from " + constructor.toString(), Object.keys(props).indexOf('id') === -1);

@bmac
Copy link
Member

bmac commented Sep 6, 2015

ping @igorT I'd like you to review this pr if you have time.

… save request

closes emberjs#3694
- uses es5 getters and setters to be able to set the internalModel id
- add assertion that model is new before setting id
}
},
get() {
if (this._internalModel) {
Copy link
Member

Choose a reason for hiding this comment

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

This should never be false

igorT added a commit that referenced this pull request Sep 8, 2015
[BUGFIX release] fix regression where dynamically set id is not serialized in a create…
@igorT igorT merged commit c208f2c into emberjs:master Sep 8, 2015
bmac added a commit that referenced this pull request Sep 8, 2015
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.

Dynamically set DS.Model id's don't seem to be serialized in a createRecord POST request
5 participants