With Ember Data, I would like to know how to delete a record given that I know its id.
One way to think about the store is as a cache of all of the records that have been loaded by your application. If a route or a controller in your app asks for a record, the store can return it immediately if it is in the cache.
Ember does not provide tools for the backend at all, it's meant to be front-end framework only.
A Service is an Ember object that lives for the duration of the application, and can be made available in different parts of your application. Services are useful for features that require shared state or persistent connections. Example uses of services might include: User/session authentication. Geolocation.
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.
http://jsbin.com/iwiruw/460/edit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With