Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
loadRelations from collections and integers more testing.
  • Loading branch information
adrigzr committed Nov 26, 2014
commit f36a5a3d022d92b83e0fa9f0e93014d5ea0c9855
9 changes: 5 additions & 4 deletions src/datastore/async_methods/loadRelations.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ function loadRelations(resourceName, instance, relations, options) {
}

if (DSUtils.isArray(instance)) {
var instances = [];
angular.forEach(instance, function(object) {
instances.push(DS.get(resourceName, object));
instance = instance.map(function(object) {
if (DSUtils.isString(object) || DSUtils.isNumber(object)) {
object = DS.get(resourceName, object);
}
return object;
});
instance = instances;
}

if (!definition) {
Expand Down
18 changes: 17 additions & 1 deletion test/integration/datastore/async_methods/loadRelations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ describe('DS.loadRelations(resourceName, instance(Id), relations[, options]): ',

$httpBackend.flush();
});
it('should load relations from array of objects', function () {
it('should load relations from array of integers', function () {
DS.inject('user', user10);
DS.inject('user', user16);

Expand All @@ -223,6 +223,22 @@ describe('DS.loadRelations(resourceName, instance(Id), relations[, options]): ',
assert.equal(users[1].organization.id, organization15.id);
}, fail);

$httpBackend.flush();
});
it('should load relations from collection', function () {
DS.inject('user', user10);
DS.inject('user', user16);

$httpBackend.expectGET('http://test.angular-cache.com/organization/14').respond(200, organization14);
$httpBackend.expectGET('http://test.angular-cache.com/organization/15').respond(200, organization15);

DS.loadRelations('user', [user10, user16], ['organization']).then(function (users) {
assert.isObject(users[0].organization);
assert.equal(users[0].organization.id, organization14.id);
assert.isObject(users[1].organization);
assert.equal(users[1].organization.id, organization15.id);
}, fail);

$httpBackend.flush();
});
});