Reputation: 38583
I need to delete a model when I leaving a route. I am using the following in the route:
actions : {
willTransition: function(transition){
//Cleanup search model
var model = this.modelFor('route1.index');
model.deleteRecord();
//At this point the model.get('isDeleted') = true
}
}
From ember inspector when I have transitioned to my new route route1.route2
, I can still see the model and its isDeleted
property is now false.
Why is this not working?
Upvotes: 0
Views: 90
Reputation: 11
You need to call the save()
method after calling deleteRecord()
actions : {
willTransition: function(transition){
//Cleanup search model
var model = this.modelFor('route1.index');
model.deleteRecord();
model.save();
}
}
Or just use model.destroyRecord();
as it does both
Upvotes: 1
Reputation: 2824
First of all, you willTransition
will be also called before you're entering the route, so you have to make sure that the transition's target is different from the current route:
if (transition.intent.name !== this.routeName)
Then, you can probably use something like:
var model = this.modelFor(this.routeName);
instead of manually type the route name.
How did you check that the model is not deleted? Maybe you created a new one?
Upvotes: 1