1
votes

using ember-data 1.0.0-beta.5 and have the following routes and router

 App.Router.map(function () {
      this.resource('users', function () {
            this.route('new');
      });
      this.resource('user', { path: '/user/:id' }, function () {
          this.route('edit');
      });
  });

App.UsersIndexRoute = Ember.Route.extend({
    model: function(){
        return this.store.findAll('user');
     },
     setupController: function (controller, data) {
         this._super(controller, data);
     }
 });

 App.UserEditRoute = Ember.Route.extend({
     model: function() {
         return this.store.find('user', this.modelFor("user").id);
     },
     setupController: function (controller, data) {
         this._super(controller, data);
      },
      actions: {
          delete: function(){
              var router = this;
              var model = this.currentModel;
                    model.destroyRecord().then(function(){
                        router.transitionTo('users');
                    });

                }

            }
    });

However when i transition back to the users route the ArrayController still has the deleted object in it. Any ideas as to why this is or how to wait until it is removed before transitioning?

2
Is it actually being deleted from the server?Kingpin2k
yea. i do have a elastic index returning the user object however. the only thing i can think of is that there is a latency of it being removed from the index and is being returned in the /users call.Rob
I had suspected as much, are expecting to grab new users when you hit the route again, or is that not important?Kingpin2k
i would want to grab any new users. but i think my implementation handles that no?Rob
Yeah it does, I was just wondering if that was your intention (to refetch all the users).Kingpin2k

2 Answers

0
votes

kind of a work around but solves the problem.

in the UsersIndexContoller add a array to store the deleted ids

App.UsersIndexController = Ember.ArrayController.extend({
   deleted: []
});

Then just append the id of the deleted model to this array and filter in the setupController method.

 App.UsersEditRoute = Ember.Route.extend({
     delete: function(){
          var router = this;
          var model = this.currentModel;
          var usersController = this.controllerFor('users.index');

          model.destroyRecord().then(function(){
               usersController.get('deleted').push(model.id);
               router.transitionTo('users');
           });

       }

    }
 });

App.UsersIndexRoute = Ember.Route.extend({
   setupController: function (controller, data) {
      var deleted = this.controller.get('deleted');
      var filtered = data.filter(function(user){
          return  !deleted.contains(user.id);
      });
     data.set('content', filtered);
     this._super(controller, data);
   }
 });
-1
votes

In your case since you want to refetch all of the users and your server lies to you about deleting the record (or it happens later), you might contemplate transitioning then deleting.

delete: function(){  
   var model = this.currentModel;
   this.transitionTo('users').then(function(){
     model.destroyRecord();
   });
}