Skip to content

Commit

Permalink
Fix removal of destroyed records from ManyArray
Browse files Browse the repository at this point in the history
  • Loading branch information
wagenet committed May 8, 2015
1 parent 51bac6a commit 1333191
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
6 changes: 1 addition & 5 deletions packages/ember-data/lib/system/many-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, {
length: 0,

objectAt: function(index) {
if (this.currentState[index]) {
return this.currentState[index];
} else {
return this.canonicalState[index];
}
return this.currentState[index];
},

flushCanonical: function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1406,3 +1406,25 @@ test("hasMany hasData sync created", function () {
equal(relationship.hasData, true, 'relationship has data');
});
});

test("destroying an item properly updates a hasMany", function() {
expect(4);

env.adapter.deleteRecord = function() {
return { id: 1 };
};

run(function() {
var post = store.push('post', { id: 1, comments: [1] });
var comment = store.push('comment', { id: 1, post: 1 });

equal(post.get('comments.length'), 1);
equal(post.get('comments.firstObject'), comment);

comment.destroyRecord().then(function() {
// Make sure to check both since sometimes they've not been in sync
equal(post.get('comments.length'), 0);
equal(post.get('comments.firstObject'), null);
});
});
});

0 comments on commit 1333191

Please sign in to comment.