1
votes

I have this route that currently, when I transition back to it, gives me this great big error with a stack trace that doesn't help me figure out what is going wrong.

Error while processing route: project.details Assertion Failed: calling set on destroyed object Error: Assertion Failed: calling set on destroyed object at new Error (native) at Error.EmberError (http://starqa.fmr.com/assets/vendor.js:22615:21) at Object.Ember.default.assert (http://starqa.fmr.com/assets/vendor.js:15716:13) at Object.set (http://starqa.fmr.com/assets/vendor.js:26367:22) at exports.default.mixin.Mixin.create.set (http://starqa.fmr.com/assets/vendor.js:41034:20) at Ember.Object.extend.flushCanonical (http://starqa.fmr.com/assets/vendor.js:69769:14) at ember$data$lib$system$relationships$state$has_many$$ManyRelationship.flushCanonical (http://starqa.fmr.com/assets/vendor.js:71525:22) at Queue.invoke (http://starqa.fmr.com/assets/vendor.js:11425:18) at Object.Queue.flush (http://starqa.fmr.com/assets/vendor.js:11490:13) at Object.DeferredActionQue

Through just going through my routes and commenting out stuff, I found this in my projects route:

export default Ember.Route.extend(AuthenticatedRouteMixin, {
  model: function(params) {
    if (params.q) {
      return this.store.find('project', params);
    } else {
      var _this = this;
      Ember.run(function() {
        _this.store.unloadAll('project');
      });
      return this.store.findAll('project', {reload: true});
    }
  }

And if I comment out lines 7-9:

/*
  Ember.run(function() {
    _this.store.unloadAll('project');
  });
*/

then the error goes away and the transition worked. This bit of code was written by somebody else, and I think it has to do with refreshing the model from the store, but I can't figure out why it would cause this "calling set on a destroyed object" error.

Any help would be greatly appreciated.

1

1 Answers

1
votes

Offhand it looks like this route serves both single project param (q is specified) and all projects, which offhand sounds like far from perfect design for ember. Ideally you should have two routes - the projects and project route. That's on the Ember architecture side.

On the functional side, this happens when you object was released by ember yet you try and access it a second time. I suspect this is happening as the Ember.run, runs the unload all in another loop, whereas I don't think that's what's needed. Try to remove the unload all from the ember loop, or most chances you can just run without it at all (as why do you want to remove all the object in the current cache each time you call the route?

this.store.unloadAll('project');
return this.store.findAll('project', {reload: true});

Or just leave it commented out (I think leaving it commented should work for you).