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

Id is abscent in payload on saving a new model #3360

Closed
novtor opened this issue Jun 16, 2015 · 12 comments
Closed

Id is abscent in payload on saving a new model #3360

novtor opened this issue Jun 16, 2015 · 12 comments

Comments

@novtor
Copy link

novtor commented Jun 16, 2015

When I create a model

var newPost = this.store.createRecord('post', {
'id': '',
'name':'good post'
});
newPost.set('id', 'qwerty');
newPst.save();

the id 'qwerty' is abscent in the server call.
Is it expected behavior?

@btecu
Copy link
Contributor

btecu commented Jun 16, 2015

You don't have to pass: 'id': '' when you create the record.
Also, it may just be a typo, but I see you're calling save on newPst instead of newPost (maybe you have multiple new records?).

@bmac
Copy link
Member

bmac commented Jun 16, 2015

Hi @novtor, that does not seem like expected behavior. Would you be able to make a jsbin demonstrating the issue? Here is a jsbin to get you started http://emberjs.jsbin.com/navucuvoso/1/edit?html,js

@novtor
Copy link
Author

novtor commented Jun 17, 2015

Hi @btecu, @bmac. Thank you for your replies. In my usecase I need to precise the id of the record being saved.
Here is the example to reproduce:
http://emberjs.jsbin.com/qaqiyi/edit?html,js,output
Thank you @bmac for the sample. Click on the 'new author' and enter an id and a name, on 'save' click it tries to save this entity and the payload is shown in the alert popup (except that firefox tells me that window.alert is not a function-((( but chrome do the job).

@sly7-7
Copy link
Contributor

sly7-7 commented Jun 17, 2015

@novtor for creating a model with a primaryKey, I think you must pass the id in the createRecorddata hash. I don't think you can modify the primaryKey after a record is created. At least, internally, only the original id is put in the internalModel, and looks immutable. Then when we serialize the record, we create the snapshot on the internalModel, which has the original id. I don't know if we want it to track the record's id change.
cc/ @igorT @wecc

@novtor
Copy link
Author

novtor commented Jun 17, 2015

Hi @sly7-7 thank you for your reply. So it looks to be expected.
And just realised I forgot to precise that it used to work fine before 1.0.0-beta.19.

@sly7-7
Copy link
Contributor

sly7-7 commented Jun 17, 2015

Hmm, so if it used to work pre beta.19, that should mean it is maybe something we forgot when introducing internalModels.

@e3b0c442
Copy link

+1, I am currently experiencing this issue as well, starting with ED 1.0.0-beta.19. ids were mutable in 1.0.0-beta.18 and previous, but not with 1.0.0-beta.19 and newer.

@e3b0c442
Copy link

@sly7-7 It would seem to me that having the id be immutable after the record is committed would be appropriate, but before committing I think we should be able to change it.

@sly7-7
Copy link
Contributor

sly7-7 commented Jul 16, 2015

@wecc Do you have any thoughts on this ?

@wecc
Copy link
Contributor

wecc commented Jul 16, 2015

No, need to poke @igorT brain to understand Modal/InternalModel better.

@jgelens
Copy link

jgelens commented Aug 4, 2015

I can confirm this issue too. Imo the id should be immutable after saving (POST) for the first time. But right after createRecord it still should be callable.

@wecc
Copy link
Contributor

wecc commented Sep 8, 2015

Closing as I'm pretty sure this have been fixed by #3701, please re-open if I'm mistaken.

@wecc wecc closed this as completed 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

No branches or pull requests

7 participants