Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for removing and unloading a record from a hasMany relationship #4987

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions tests/integration/relationships/has-many-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1788,6 +1788,37 @@ testInDebug('A sync hasMany errors out if there are unlaoded records in it', fun
}, /You looked up the 'comments' relationship on a 'post' with id 1 but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async \('DS.hasMany\({ async: true }\)'\)/);
});

test('After removing and unloading a record, a hasMany relationship should still be valid', function(assert) {
const post = run(() => {
env.store.push({
data: {
type: 'post',
id: '1',
relationships: {
comments: {
data: [
{ type: 'comment', id: '1' }
]
}
}
},
included: [
{ type: 'comment', id: '1' }
]
});
const post = env.store.peekRecord('post', 1);
const comments = post.get('comments');
const comment = comments.objectAt(0);
comments.removeObject(comment);
env.store.unloadRecord(comment);
assert.equal(comments.get('length'), 0);
return post;
});

// Explicitly re-get comments
assert.equal(run(post, 'get', 'comments.length'), 0);
});

test("If reordered hasMany data has been pushed to the store, the many array reflects the ordering change - sync", function(assert) {
var comment1, comment2, comment3, comment4;
var post;
Expand Down