How do we commit store changes with Ember-data 1.0.0-beta1?

Here the code from our simple application

App.js:

/* Model */
App.User = DS.Model.extend({
  first_name: DS.attr('string'),
  last_name: DS.attr('string'),  	

  fullName: function() {
    return this.get('first_name') + ' ' + this.get('last_name');
  }.property('first_name', 'last_name'),
});

/* Controller */    
App.UsersController = Ember.ArrayController.extend({
  actions: {
    deleteUser: function(model) {
      this.store.deleteRecord(model);
    }
  }
});

When the deleteUser action is triggered from the template, the model is deleted from the store but no HTTP request is made to sync data with the server.

How do we commit changes? I found some transactions examples but it looks like ember-data 1.0.0 doesn’t support them anymore.

You need to delete and then save. @cyclomarc outlines it well in his post (8. Deleting a record): Migrating from Ember Data 0.13 to 1.0.0 Beta 1 - My findings

1 Like

It works! Thank you.

I have another issue: I used the then function on the save function as showed on the link and the record is deleted (the DELETE HTTP request returns 200 OK) but the error callback is always called.

What’s the error message in the rejected callback?

This is what I do:

model.save().then(function() {
      console.log("ok");
    }).fail(function(error) {
      console.log(JSON.stringify(error));
    }
);

and this is what is printed in the console:

   {"readyState":4,"then":null,"responseText":"","status":200,"statusText":"OK"} 

Same thing with:

model.save().then(
    function() {
      console.log("ok");
    },
    function(error) {
      console.log(JSON.stringify(error));
    }
);

Anybody else had this issue?

@Frandre yes. I changed the JSON response to return the deleted record, and then was invoked afterwards.

Do you have any adapters or serializers for the model that you’re saving? If so, it’s very possible that something in either of them could be causing this issue.

It looks like your server returns a payload that doesn’t match up with Ember Data’s standard, so you’ll need to override the normalizePayload method in the serializer for this model if you haven’t done so already.