Reputation: 1009
When I create a new DS.Model record and call commit on the store I would like to know when the record was created in the persistence layer and I have access to the id
attribute.
I thought the didCreate
callback would do exactly that. But to my surprise the id
is still undefined
when the didCreate
gets invoked.
So my question is basically, am I doing something wrong and there is a better callback for my use-case or is this a bug?
Upvotes: 3
Views: 1012
Reputation: 16143
Hmm, it looks like this test case should cover this. I think you should file a ticket.
As a workaround you could use something along those lines, see http://jsfiddle.net/pangratz666/ZkQHE/:
App.IdWatcher = Ember.Mixin.create({
init: function() {
this._super();
this.addObserver('data', this, '_dataDidChange');
},
_dataDidChange: function() {
var id = this.get('id');
if (id) {
this.idHasBeenDefined(id);
this.removeObserver('data', this, '_dataDidChange');
}
}
});
App.Model = DS.Model.extend(App.IdWatcher, {
label: DS.attr('string'),
idHasBeenDefined: function(id) {
console.log('id is set to %@'.fmt(id));
}
});
Upvotes: 2