Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 6847286

Browse files
aarspixelhandler
authored andcommitted
bugfix: Track changed hasOne without 'previous' (#111)
1 parent d5aaf15 commit 6847286

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

addon/models/resource.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ const Resource = Ember.Object.extend(ResourceOperationsMixin, {
370370
get() {
371371
let relationships = Object.keys(this._relationships).filter( (relation) => {
372372
let ref = this._relationships[relation];
373-
return !!ref.previous || (ref.removals && ref.removals.length) ||
373+
return !!ref.changed || (ref.removals && ref.removals.length) ||
374374
(ref.added && ref.added.length);
375375
});
376376
return Ember.A(relationships);

tests/unit/models/resource-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,19 @@ test('#addRelationship tracks relationships changes', function(assert) {
313313
assert.equal(post._relationships.author.changed.id, '1', 'changed id is 1');
314314
assert.equal(post._relationships.author.changed.type, 'authors', 'changed type is authors');
315315

316+
let changed = post.get('changedRelationships');
317+
assert.equal(changed.length, 1, 'one changedRelationship');
318+
assert.equal(changed[0], 'author', 'changedRelationship is "author"');
319+
316320
post.addRelationship('comments', '1');
317321
assert.ok(post._relationships.comments.added, 'comments relation added');
318322
assert.equal(post._relationships.comments.added.length, 1, 'one comments relation added');
323+
324+
changed = post.get('changedRelationships');
325+
assert.equal(changed.length, 2, 'two changedRelationships');
326+
assert.equal(changed.filter(i => { return i==="comments"; }).length,
327+
'1', 'changedRelationships contains "comments"');
328+
319329
post.addRelationship('comments', '2');
320330
assert.equal(post._relationships.comments.added.length, 2, 'two comments relation added');
321331
});

0 commit comments

Comments
 (0)