diff --git a/addon/-private/system/relationships/state/relationship.js b/addon/-private/system/relationships/state/relationship.js index 5891d8ed8b3..d6c97f5e7b9 100644 --- a/addon/-private/system/relationships/state/relationship.js +++ b/addon/-private/system/relationships/state/relationship.js @@ -130,6 +130,7 @@ export default class Relationship { } inverseDidDematerialize(inverseInternalModel) { + this.linkPromise = null; if (!this.isAsync) { // unloading inverse of a sync relationship is treated as a client-side // delete, so actually remove the models don't merely invalidate the cp diff --git a/tests/integration/records/unload-test.js b/tests/integration/records/unload-test.js index e663aa34724..34e98b168cc 100644 --- a/tests/integration/records/unload-test.js +++ b/tests/integration/records/unload-test.js @@ -2009,33 +2009,12 @@ test('1 sync : many async unload sync side', function(assert) { ); }); -test('unload should work with observers on hasMany', function(assert) { +test('unload invalidates link promises', function(assert) { let isUnloaded = false; env.adapter.coalesceFindRequests = false; - env.adapter.findRecord = (store, type, id) => { - assert.equal(type, Boat, 'findRecord(_, type) is correct'); - - if (id === '2' && isUnloaded) { - throw "not found"; - } - - let relationships = { - person: { - data: { - type: 'person', - id: '1' - } - } - }; - - return { - data: { - type: 'boat', - id: id, - relationships - } - } + env.adapter.findRecord = (/* store, type, id */) => { + assert.notOk('Records only expected to be loaded via link'); }; env.adapter.findHasMany = (store, snapshot, link) => { @@ -2080,14 +2059,6 @@ test('unload should work with observers on hasMany', function(assert) { relationships: { boats: { links: { related: 'boats' } -// data: [{ -// id: 2, -// type: 'boat' -// },{ -// id: 3, -// type: 'boat' -// }, -// ] } } } @@ -2095,12 +2066,6 @@ test('unload should work with observers on hasMany', function(assert) { ); let boats, boat2, boat3; - person.addObserver('boats.[]', function() { - person.get('boats'); - //NOTE: using a runloop seems to fix it -// run(() => person.get('boats')); - }); - return run(() => person.get('boats').then((asyncRecords) => { boats = asyncRecords; @@ -2111,11 +2076,12 @@ test('unload should work with observers on hasMany', function(assert) { assert.equal(boat3.belongsTo('person').id(), '1', 'initially relationship established rhs'); isUnloaded = true; - run(() => boat2.unloadRecord()); + run(() => { + boat2.unloadRecord(); + person.get('boats'); + }); assert.deepEqual(boats.mapBy('id'), ['3'], 'unloaded boat is removed from ManyArray'); - //TODO: remove reload if ED fixes invalidate bug - return person.hasMany('boats').reload(); }).then(() => { return run(() => person.get('boats')); }).then(newBoats => {