0
votes

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?

1
can you do store.find(App.Foo, 1).then(function(data){data.deleteRecord();});mehulkar
in rev 11, i'm using deleteRecord all over the place for records that weren't commited, btw. But I usually have a handle on the instance of that record without having to call findmehulkar
As I am thinking about it, deleteRecord should be working too as Mehul is saying. It works for me.Myslik
@ToranBillups This fiddle may help. I've added something similar in the ContactsAddRouteMilkyWayJoe

1 Answers

4
votes

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.