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

Notify the RecordArray once it has been loaded from Server #374

Closed
wants to merge 1 commit into from
Closed
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 packages/ember-data/lib/adapters/fixture_adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ DS.FixtureAdapter = DS.Adapter.extend({

this.simulateRemoteCall(function() {
store.loadMany(type, fixtures);
store.typeMapFor(type).findAllCache.set('didFindAllRecords', true);
}, store, type);
},

Expand Down
1 change: 1 addition & 0 deletions packages/ember-data/lib/adapters/rest_adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ DS.RESTAdapter = DS.Adapter.extend({
success: function(json) {
this.sideload(store, type, json, plural);
store.loadMany(type, json[plural]);
store.typeMapFor(type).findAllCache.set('didFindAllRecords', true);
}
});
},
Expand Down
3 changes: 3 additions & 0 deletions packages/ember-data/lib/system/record_arrays/record_array.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ DS.RecordArray = Ember.ArrayProxy.extend({
// The store that created this record array.
store: null,

// Has the recordArray been loaded via findAll.
didFindAllRecords: false,

objectAtContent: function(index) {
var content = get(this, 'content'),
clientId = content.objectAt(index),
Expand Down
13 changes: 13 additions & 0 deletions packages/ember-data/tests/unit/rest_adapter_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,19 @@ test("finding all people makes a GET to /people", function() {
equal(person, store.find(Person, 1), "the record is now in the store, and can be looked up by ID without another Ajax request");
});

test("finding all sets the recordArray's didFindAllRecords flag", function() {
people = store.find(Person);

equal(false, people.get('didFindAllRecords'), "didFindAllRecords is initially false");

expectUrl("/people", "the plural of the model name");
expectType("GET");

ajaxHash.success({ people: [{ id: 1, name: "Yehuda Katz" }] });

equal(true, people.get('didFindAllRecords'), "The RecordArray was informed of the successful request");
});

test("finding all can sideload data", function() {
var groups = store.find(Group);

Expand Down