From 02c6f269fa9be3f5117feb8b81a78141c3b1412a Mon Sep 17 00:00:00 2001 From: Chris Santero Date: Fri, 7 Jul 2017 14:58:55 -0700 Subject: [PATCH] set hasData even when has-many link returns empty array --- .../system/relationships/state/has-many.js | 1 + tests/integration/references/has-many-test.js | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) mode change 100644 => 100755 addon/-private/system/relationships/state/has-many.js mode change 100644 => 100755 tests/integration/references/has-many-test.js diff --git a/addon/-private/system/relationships/state/has-many.js b/addon/-private/system/relationships/state/has-many.js old mode 100644 new mode 100755 index 170011cd561..89f7e511e68 --- a/addon/-private/system/relationships/state/has-many.js +++ b/addon/-private/system/relationships/state/has-many.js @@ -202,6 +202,7 @@ export default class ManyRelationship extends Relationship { this.store._backburner.join(() => { this.updateInternalModelsFromAdapter(records); this.manyArray.set('isLoaded', true); + this.setHasData(true); }); return this.manyArray; }); diff --git a/tests/integration/references/has-many-test.js b/tests/integration/references/has-many-test.js old mode 100644 new mode 100755 index a2ad4339254..19a756c14de --- a/tests/integration/references/has-many-test.js +++ b/tests/integration/references/has-many-test.js @@ -662,6 +662,40 @@ test("load() fetches link when remoteType is link", function(assert) { }); }); +test("load() fetches link when remoteType is link but an empty set of records is returned", function(assert) { + env.adapter.findHasMany = function(store, snapshot, link) { + assert.equal(link, "/families/1/persons"); + + return Ember.RSVP.resolve({ data: [] }); + }; + + let family; + run(() => { + family = env.store.push({ + data: { + type: 'family', + id: 1, + relationships: { + persons: { + links: { related: '/families/1/persons' } + } + } + } + }); + }); + + let personsReference = family.hasMany('persons'); + assert.equal(personsReference.remoteType(), "link"); + + return run(() => { + return personsReference.load().then((records) => { + assert.ok(records instanceof DS.ManyArray, "push resolves with the referenced records"); + assert.equal(get(records, 'length'), 0); + assert.equal(get(personsReference.value(), 'length'), 0); + }); + }); +}); + test("load() - only a single find is triggered", function(assert) { var done = assert.async();