Skip to content

Commit f36a5a3

Browse files
committed
loadRelations from collections and integers more testing.
1 parent d98aee7 commit f36a5a3

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/datastore/async_methods/loadRelations.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@ function loadRelations(resourceName, instance, relations, options) {
7575
}
7676

7777
if (DSUtils.isArray(instance)) {
78-
var instances = [];
79-
angular.forEach(instance, function(object) {
80-
instances.push(DS.get(resourceName, object));
78+
instance = instance.map(function(object) {
79+
if (DSUtils.isString(object) || DSUtils.isNumber(object)) {
80+
object = DS.get(resourceName, object);
81+
}
82+
return object;
8183
});
82-
instance = instances;
8384
}
8485

8586
if (!definition) {

test/integration/datastore/async_methods/loadRelations.test.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ describe('DS.loadRelations(resourceName, instance(Id), relations[, options]): ',
209209

210210
$httpBackend.flush();
211211
});
212-
it('should load relations from array of objects', function () {
212+
it('should load relations from array of integers', function () {
213213
DS.inject('user', user10);
214214
DS.inject('user', user16);
215215

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

226+
$httpBackend.flush();
227+
});
228+
it('should load relations from collection', function () {
229+
DS.inject('user', user10);
230+
DS.inject('user', user16);
231+
232+
$httpBackend.expectGET('http://test.angular-cache.com/organization/14').respond(200, organization14);
233+
$httpBackend.expectGET('http://test.angular-cache.com/organization/15').respond(200, organization15);
234+
235+
DS.loadRelations('user', [user10, user16], ['organization']).then(function (users) {
236+
assert.isObject(users[0].organization);
237+
assert.equal(users[0].organization.id, organization14.id);
238+
assert.isObject(users[1].organization);
239+
assert.equal(users[1].organization.id, organization15.id);
240+
}, fail);
241+
226242
$httpBackend.flush();
227243
});
228244
});

0 commit comments

Comments
 (0)