Store create record without save to server, how can I delete the new record?


#1

I create a record like this:

var post = this.store.createRecord(‘post’, { id:UUID() }); // without save // post.save();

How can I delete the ‘post’ record? Did the record saved in the store? If I call the store.commit function, Will the new record request the server to save.


#2

You can remove that newly created record that hasn’t been saved by doing this:

model.rollback();
if (model.get('isNew')) {
  model.deleteRecord();
}

Here’s a link that might help you out as well: http://reefpoints.dockyard.com/2014/03/03/a-simple-ember-data-route.html


#3

You can use rollback.

post.rollback()

If model is new, it will be removed from the store.


#4

Thanks, barryofguilder and midd, that’s helpful for me.