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

Set hasData for preloaded empty hasMany #5060

Merged
merged 1 commit into from
Jul 13, 2017
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions addon/-private/system/relationships/state/relationship.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ export default class Relationship {

updateInternalModelsFromAdapter(internalModels) {
heimdall.increment(updateInternalModelsFromAdapter);
this.setHasData(true);
//TODO(Igor) move this to a proper place
//TODO Once we have adapter support, we need to handle updated and canonical changes
this.computeChanges(internalModels);
Expand Down
53 changes: 53 additions & 0 deletions tests/unit/store/adapter-interop-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,59 @@ test('initial values of hasMany can be passed in as the third argument to find a
return run(() => store.findRecord('person', 1, { preload: { friends: [2] } }));
});

test('initial empty values of hasMany can be passed in as the third argument to find as records', function(assert) {
assert.expect(1);

const Adapter = TestAdapter.extend({
findRecord(store, type, id, snapshot) {
assert.equal(snapshot.hasMany('friends').length, 0, 'Preloaded hasMany set');
return { data: { id, type: 'person' } };
}
});

let env = setupStore({
adapter: Adapter
});

let { store } = env;

const Person = DS.Model.extend({
name: DS.attr('string'),
friends: DS.hasMany('person', { inverse: null, async: true })
});

env.registry.register('model:person', Person);

return run(() => {
return store.findRecord('person', 1, { preload: { friends: [] } });
});
});

test('initial values of hasMany can be passed in as the third argument to find as ids', function(assert) {
assert.expect(1);

const Adapter = TestAdapter.extend({
findRecord(store, type, id, snapshot) {
assert.equal(snapshot.hasMany('friends').length, 0, 'Preloaded hasMany set');
return { data: { id, type: 'person' } };
}
});

let env = setupStore({
adapter: Adapter
});
let { store } = env;

const Person = DS.Model.extend({
name: DS.attr('string'),
friends: DS.hasMany('person', { async: true, inverse: null })
});

env.registry.register('model:person', Person);

return run(() => store.findRecord('person', 1, { preload: { friends: [] } }));
});

test('records should have their ids updated when the adapter returns the id data', function(assert) {
assert.expect(2);

Expand Down