Skip to content

Commit

Permalink
Don't assume the returned records from a findMany call match the same…
Browse files Browse the repository at this point in the history
… order as the list of ids sent to the server
  • Loading branch information
bradleypriest authored and tchak committed May 3, 2012
1 parent 8ecdbc8 commit ab04ffa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/ember-data/lib/adapters/rest_adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ DS.RESTAdapter = DS.Adapter.extend({
this.ajax(this.buildURL(root), "GET", {
data: { ids: ids },
success: function(json) {
store.loadMany(type, ids, json[plural]);
store.loadMany(type, json[plural]);
this.sideload(store, type, json, plural);
}
});
Expand Down
29 changes: 29 additions & 0 deletions packages/ember-data/tests/unit/rest_adapter_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,35 @@ test("finding many people by a list of IDs", function() {
});
});

test("finding many people by a list of IDs doesn't rely on the returned array order matching the passed list of ids", function() {
store.load(Group, { id: 1, people: [ 1, 2, 3 ] });

var group = store.find(Group, 1);

var people = get(group, 'people');

ajaxHash.success({
people: [
{ id: 2, name: "Tom Dale" },
{ id: 1, name: "Rein Heinrichs" },
{ id: 3, name: "Yehuda Katz" }
]
});

var rein = people.objectAt(0);
equal(get(rein, 'name'), "Rein Heinrichs");
equal(get(rein, 'id'), 1);

var tom = people.objectAt(1);
equal(get(tom, 'name'), "Tom Dale");
equal(get(tom, 'id'), 2);

var yehuda = people.objectAt(2);
equal(get(yehuda, 'name'), "Yehuda Katz");
equal(get(yehuda, 'id'), 3);

});

test("additional data can be sideloaded in a GET with many IDs", function() {
//store.load(Group, { id: 1, people: [ 1, 2, 3 ] });

Expand Down

0 comments on commit ab04ffa

Please sign in to comment.