jeudi 29 janvier 2015

Ember - after saving model, how to get id in success callback from promise

Simple scenario in Ember-1.9.2, Ember-Data 1.0.0-beta.14.1:



model.save().then(function(savedModel){
debugger
self.transitionToRoute('model', savedModel);
}).catch(failure);

function failure(reason) {
this.set('showError', true);
}


Why can't I get the id of the saved model in the success callback (where the debugger statement is) ? It does transition successfully, but with a null id in the route. This then causes problems if you want to edit the newly created model, after transitioning.


Have also tried reloading the savedModel in the callback, which is not actually possible without the model's id. It seems as though the id isn't available until the Store is reloaded on the synchronous page refresh, updating it with the server and the server's id for the model. How is this possible to update the store within the callback?





Aucun commentaire:

Enregistrer un commentaire