Skip to content

Commit

Permalink
[BUGFIX release] Guard against isDestroyed in ManyArray.flushCanonical
Browse files Browse the repository at this point in the history
Addresses emberjs#3084
  • Loading branch information
jgwhite committed Sep 2, 2015
1 parent 6dac777 commit 251a06e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/ember-data/lib/system/many-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, {
toSet = toSet.concat(newRecords);
var oldLength = this.length;
this.arrayContentWillChange(0, this.length, toSet.length);
this.set('length', toSet.length);
if (!this.isDestroyed) {
this.set('length', toSet.length);
}
this.currentState = toSet;
this.arrayContentDidChange(0, oldLength, this.length);
//TODO Figure out to notify only on additions and maybe only if unloaded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2340,3 +2340,65 @@ test("metadata should be reset between requests", function() {
});
});
});

test("unloading and reloading a record with hasMany relationship", function() {
var user;
var message;

run(function() {
env.store.push({
data: [{
type: 'user',
id: 'user-1',
attributes: {
name: 'Adolfo Builes'
},
relationships: {
messages: {
data: [
{ type: 'message', id: 'message-1' }
]
}
}
}, {
type: 'message',
id: 'message-1'
}]
});

user = env.store.peekRecord('user', 'user-1');
message = env.store.peekRecord('message', 'message-1');

equal(get(user, 'messages.firstObject.id'), 'message-1');
equal(get(message, 'user.id'), 'user-1');
});

run(function() {
env.store.unloadRecord(user);
});

run(function() {
// The record is resurrected for some reason.
env.store.push({
data: [{
type: 'user',
id: 'user-1',
attributes: {
name: 'Adolfo Builes'
},
relationships: {
messages: {
data: [
{ type: 'message', id: 'message-1' }
]
}
}
}]
});

user = env.store.peekRecord('user', 'user-1');

equal(get(user, 'messages.firstObject.id'), 'message-1');
equal(get(message, 'user.id'), 'user-1');
});
});

0 comments on commit 251a06e

Please sign in to comment.