Ember.js "call set on destroyed object" error after call to unload Record
As part of a session system, for a project I'm working on, I call unloadRecord
on an entry like this:
user.unloadRecord();
I am not calling destroyRecord
because I want to manually unload the record from storage without storing it on the server. Deleting an entry from the store this way works fine, but when I log into the same account that requires downloading the same user record from the server and manually inserting it into the store using store.push
- I get the following error message:
Uncaught Error: Assertion Failed: calling set on destroyed object ember.js:3902
Again, this happens on the next line after the call user.unloadRecord()
:
var user = this.store.push("user", response.user);
Where response
is the JSON payload returned by the request POST
to / session, an example of which is shown here:
{
"sessionToken":"f7a7247467b08818ead27441838df30fed0e0a79",
"user": {
"id":"5499bf5b7f25680761c9df7a",
"email":"test@gmail.com",
"accounts": [/* [account ids] */],
"syncPaths":[/* [sync path ids] */]
}
}
Is there a way to avoid this error?
UPDATE
In response to requests to see more code here is the file containing the call unloadRecord
and here is the file containing the call store.push
.
UPDATE 2 : I've included an example JSON payload returned by a POST request to / session, upon request. Here's a model for user
:
DS.Model.extend({
email: DS.attr("string"),
accounts: DS.hasMany("account"),
syncPaths: DS.hasMany("syncPaths")
});
source to share
I've struggled with something similar though with unloadAll()
. Someone suggested this, so maybe this will help you.
In the source code, ember.js
or ember.debug.js
if it is running locally, find the following line:
Ember['default'].assert('calling set on destroyed object', !obj.isDestroyed);
and change it to:
Ember['default'].assert("calling set ('" + keyName + "') on destroyed object", !obj.isDestroyed);
Then you will see that the property is set and this can help you track down where in your code it is hanging. For me keyName
, it's just "length", which isn't very useful.
source to share