Response from server while saving record for setting id

After saving the record using selection.save() , where the selection is my model, the identifier is not set on the model. My current server response is the same as json to show. ie: selection: {id: <id>} and other fields. The purchase ID is not set in the local ember data store. I use the standard RESTAdapter and Rails as a backend. (I am using jbuilder for JSON)

MatchPlayerSelection model, and as soon as 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} 
+6
source share
1 answer

How do you test id set? The save function is asynchronous and returns a promise, so you need to resolve the promise before checking id .

This will NOT work:

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

This work WILL:

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

Source: https://habr.com/ru/post/956171/


All Articles