DS.Model callback, which is called after the record is created and the server-side identifier is set

When I create a new DS.Model record and commit the call to the repository, I would like to know when the record was created at the persistence level, and I have access to the attribute id.

I thought the callback didCreatewould do just that. But, to my surprise, idstill undefinedwhen called didCreate.

So, my question is basically, am I doing something wrong, and is there a better callback for my use case or is it a mistake?

+3
source share
1 answer

Hmm, it looks like this test should cover this. I think you should file a ticket.

- , . 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));
    }
});
+2

All Articles