Search code examples
ember.jsember-model

Deleting a record with ember-model


I try to delete a record, a DELETE request is sent to the server but the request seems not correct:

What is done: DELETE /books + body json format

What I expect: DELETE /books/123 + no body

  1. What is really expected in ember-model ?
  2. How can I achieve my expectation (DELETE books/123)

Solution

  • Looking at the source code, it seams clear how ember-model does the DELETE operation:

    deleteRecord: function(record) {
      var primaryKey = get(record.constructor, 'primaryKey'),
      url = this.buildURL(record.constructor, get(record, primaryKey)),
      self = this;
    
      return this.ajax(url, record.toJSON(), "DELETE").then(function(data) {
        self.didDeleteRecord(record, data);
      });
    }
    

    basically the resulting format is: DELETE /books/123 + JSON body. If your backend expects something else then the only way to change it would be to rewrite the deleteRecord for your custom needs. But IMO the simplest thing you could do is to just ignore the JSON body.

    Hope it helps.