Skip to content

Commit

Permalink
set hasData even when has-many link returns empty array
Browse files Browse the repository at this point in the history
  • Loading branch information
csantero committed Jul 7, 2017
1 parent e1699cb commit 02c6f26
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions addon/-private/system/relationships/state/has-many.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
34 changes: 34 additions & 0 deletions tests/integration/references/has-many-test.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 02c6f26

Please sign in to comment.