benihana21
benihana21

Reputation: 168

Ember Data error when deleting model

I have an Ember-cli app (v2.1), and I'm having an issue with Ember Data when deleting a record from my blog model. Here's the code I'm calling for the deletion:

deleteBlog (blog) {
  this.store.findRecord('blog', blog.get('id')).then(blog => {
    blog.destroyRecord();
  });
}

As expected, Ember Data makes the DELETE request, which works perfectly with my express.js backend service.

The only problem is that the record does not get removed from the Ember Data store, and I get the following error message:

Error: Attempted to handle event pushedData on my-app@model:blog::ember529:56455037f9cf29a325ae72b9 while in state root.deleted.inFlight

I appreciate any feedback!

Upvotes: 2

Views: 1129

Answers (2)

benihana21
benihana21

Reputation: 168

The problem was in trying to select the model using an instance of the model that I already had. Changing it to a simple:

 deleteBlog (blog) {
   blog.destroyRecord();
 }

got rid of the error! Thanks again to @torazaboro for helping me to take a closer look at the mistake.

Upvotes: 5

Vítor Martins
Vítor Martins

Reputation: 1440

Try this:

 deleteBlog (blog) {
   this.store.findRecord('blog', blog.get('id')).then(function(blog) {
      blog.deleteRecord(); // => remove blog from the store
      blog.save(); // => DELETE request
    });
}

But this is supposed to do the same as blog.destroyRecord(); so it may not work.

What is probably happenning is that if you have a request to the server in-flight and you delete the model then you get an exception Attempted to handle event pushedData on model while in state root.deleted.uncommitted.

Upvotes: 0

Related Questions