With Ember Data, I would like to know how to delete a record given that I know its id.
7
votes
3 Answers
10
votes
Note that after calling rec.deleteRecord()
you also need to call rec.save()
to "commit" the deletion.
this.get('store').find('model', the_id_of_the_record).then(function(rec){
rec.deleteRecord();
rec.save();
});
You can see that this is necessary by adding a record in the JSBin above (http://jsbin.com/iwiruw/458/edit), deleting it, and then reloading the page. You'll see that the record is "resurrected" after the page reloads (or if you click the "Run with JS" button). Here's a jsbin with rec.save()
added, where you can see that the records do not come back to life.
9
votes
0
votes
Please refer to Jeremy's answer where he adds the critical rec.save()
You can use:
this.get('store').find('model', the_id_of_the_record).then(function(rec){
rec.deleteRecord();
});
or
this.store.find('model', the_id_of_the_record).then(function(rec){
rec.deleteRecord();
});