Question

Let,

Restangular.one('users').getList().then(function(users) {
  $scope.user = users[0]; 
});

Another GET request:

Let: user: { id: '123' }

$scope.cars = $scope.user.getList('cars'); This would fires a GET request: /users/123/cars

where the 123 is gotten from the id property.


Question:

Is it possible to explicitely configure if my object's id property, for example: was named username.

user: { username: '123' }
Was it helpful?

Solution

A better answer would be to set the id field of a particular service.

angular.module('app')
   .service('SomeService', ['rootUrl', 'Restangular', function SomeService(rootUrl, Restangular) {
     return Restangular.withConfig(function (config) {
     config.setRestangularFields({"id": "username"});
   }).all('cars');
}]);

OTHER TIPS

You can change it for ALL objects, but not for just one object at the moment. Only option I can think of is just setting in the addElementTransformer user.id = user.username and it'll work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top