DS.Adapter#deleteRecord()

deleteRecord (store, type, snapshot) Promise

Defined in addon/adapter.js:371

Implement this method in a subclass to handle the deletion of a record.

Sends a delete request for the record to the server.

Example

app/adapters/application.js
import DS from 'ember-data';

export default DS.Adapter.extend({
  deleteRecord: function(store, type, snapshot) {
    var data = this.serialize(snapshot, { includeId: true });
    var id = snapshot.id;

    return new Ember.RSVP.Promise(function(resolve, reject) {
      Ember.$.ajax({
        type: 'DELETE',
        url: `/${type.modelName}/${id}`,
        dataType: 'json',
        data: data
      }).then(function(data) {
        Ember.run(null, resolve, data);
      }, function(jqXHR) {
        jqXHR.then = null; // tame jQuery's ill mannered promises
        Ember.run(null, reject, jqXHR);
      });
    });
  }
});

Parameters:

store DS.Store
type DS.Model
the DS.Model class of the record
snapshot DS.Snapshot

Returns:

Promise
promise
doc_EmberJs
2016-11-30 16:49:22
Comments
Leave a Comment

Please login to continue.