6
votes

After I save the record using selection.save() where selection is my model, id is not being set on the model. My current server response is same as the json for show. i.e: selection: {id: <id>} and other fields. Buy id is not set in the ember data local storage. I'm using the default RESTAdapter and Rails as backend. (I use jbuilder for JSON)

model is MatchPlayerSelection and once I save the record, this is the response I send back:

{"match_player_selection":{"id":41298,"user":3,"scheduledMatch":133,"matchPlayerScores":[3697,3696,3694,3698,3704,3719,3712,3709,3717,3707,3714],"captain":3694,"viceCaptain":3709}
1
what REST adapter are you using? what backend are you using? could you show a snippet of your production json? Is it part of a relationship or is this a top level object in the graph?Toran Billups
It is the top level object. I have updated the question with more details.Gautham
I am currently facing the same problem. Have you been able to resolve the problem?Erik
I was unable to resolve and did some workaround then and did not revisit later :(Gautham

1 Answers

3
votes

How are you testing for the id getting set? The save function is async and returns a promise, so you need to resolve the promise before checking the id.

This will NOT work:

selection.save();
console.log( selection.get('id') );

This WILL work:

selection.save().then(function(savedSelection){
  console.log( savedSelection.get('id') );
});