Toran Billups
Toran Billups

Reputation: 27399

How to deleteRecord when it was never committed on the backend?

I have a simple ember-data model (rev 12 -master as of 04/21/2013)

App.Foo = DS.Model.extend({
    name: DS.attr('string')
}).reopenClass({
    add: function(json) {
        //call create record but don't commit it
        var store = DS.get('defaultStore');
        store.createRecord(App.Foo, json);
    }
});

At some point in my application I need to remove an item from the store so I tried the usual

var foo = store.find(App.Foo, 1);
foo.deleteRecord();

But because the record is not completely loaded (server side) I get the error

Uncaught Error: Attempted to handle event deleteRecord on while in state rootState.loading. Called with undefined

If I plan to use ember-data in this way how can I "fake" the commit or mark the record as loaded manually?

Upvotes: 0

Views: 689

Answers (1)

Myslik
Myslik

Reputation: 1178

If I am not mistaken you can just do this:

var foo = store.find(App.Foo, 1);
foo.transaction.rollback();

This way the record will no longer be saved on commit.

Upvotes: 4

Related Questions