Skip to content

Commit d720703

Browse files
committed
Restangularize collection restangularizes nested elements
Fixes #224
1 parent e1b2981 commit d720703

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/restangular.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,14 @@ module.provider('Restangular', function() {
924924
return config.transformElem(localElem, true, route, service);
925925
}
926926

927+
function restangularizeCollectionAndElements(parent, element, route) {
928+
var collection = restangularizeCollection(parent, element, route);
929+
_.each(collection, function(elem) {
930+
restangularizeElem(parent, elem, route);
931+
});
932+
return collection;
933+
}
934+
927935
function getById(id, reqParams, headers){
928936
return this.customGET(id.toString(), reqParams, headers);
929937
}
@@ -1163,7 +1171,7 @@ module.provider('Restangular', function() {
11631171

11641172
service.restangularizeElement = _.bind(restangularizeElem, service);
11651173

1166-
service.restangularizeCollection = _.bind(restangularizeCollection, service);
1174+
service.restangularizeCollection = _.bind(restangularizeCollectionAndElements, service);
11671175

11681176
return service;
11691177
}

test/restangularSpec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,21 @@ describe("Restangular", function() {
103103
});
104104
});
105105

106+
describe("Local data", function() {
107+
it("Should restangularize a collection OK", function() {
108+
var collection = angular.copy(accountsModel);
109+
110+
Restangular.restangularizeCollection(null, collection, 'accounts');
111+
112+
expect(_.has(collection, 'get')).toBe(true);
113+
expect(_.has(collection[0], 'get')).toBe(true);
114+
115+
expect(collection.getRestangularUrl()).toBe('/accounts');
116+
expect(collection[0].getRestangularUrl()).toBe('/accounts/0');
117+
118+
});
119+
});
120+
106121
describe("$object", function() {
107122
it("Should work for single get", function() {
108123
var promise = Restangular.one('accounts', 1).get();

0 commit comments

Comments
 (0)