{"action":"created","issue":{"url":"https://api.github.com/repos/mgonto/restangular/issues/1381","repository_url":"https://api.github.com/repos/mgonto/restangular","labels_url":"https://api.github.com/repos/mgonto/restangular/issues/1381/labels{/name}","comments_url":"https://api.github.com/repos/mgonto/restangular/issues/1381/comments","events_url":"https://api.github.com/repos/mgonto/restangular/issues/1381/events","html_url":"https://github.com/mgonto/restangular/issues/1381","id":157625354,"number":1381,"title":"Nested decoupled service: how to?","user":{"login":"destegabry","id":4654358,"avatar_url":"https://avatars.githubusercontent.com/u/4654358?v=3","gravatar_id":"","url":"https://api.github.com/users/destegabry","html_url":"https://github.com/destegabry","followers_url":"https://api.github.com/users/destegabry/followers","following_url":"https://api.github.com/users/destegabry/following{/other_user}","gists_url":"https://api.github.com/users/destegabry/gists{/gist_id}","starred_url":"https://api.github.com/users/destegabry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/destegabry/subscriptions","organizations_url":"https://api.github.com/users/destegabry/orgs","repos_url":"https://api.github.com/users/destegabry/repos","events_url":"https://api.github.com/users/destegabry/events{/privacy}","received_events_url":"https://api.github.com/users/destegabry/received_events","type":"User","site_admin":false},"labels":[{"id":107039115,"url":"https://api.github.com/repos/mgonto/restangular/labels/waiting%20for%20infos","name":"waiting for infos","color":"fbca04","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-05-31T09:16:38Z","updated_at":"2016-12-09T05:41:31Z","closed_at":null,"body":"I'm trying to follow the documentation and after reading #139 and #1254 I'm more confused than ever.\nI have some tables on my DB, let's say User, Customer and UserCustomer (which implements an n:n relation between User and Customer).\nI have set up endpoints in my server at /user/[id], /customer/[id] and /user/[iduser]/customer/[idcustomer]\nI can CRUD on User and Customer tables using the `Restangular.service` syntax:\n\n``` javascript\nangular.module('...')\n  .factory('User', function (Restangular) {\n    return Restangular.service('user');\n  })\n  .factory('Customer', function (Restangular) {\n    return Restangular.service('customer');\n  })\n```\n\nIn my User factory I would like to define a getCustomer method which populates an user instance with a customers variable, pointing to a collection of Customer.\nSeems I can do something like:\n\n``` javascript\nangular.module('...')\n  .factory('User', function (Restangular) {\n    Restangular.extendModel('user', function(model) {\n      if (model.customers) {\n        Restangular.restangularizeCollection(null, model.customers, 'customer');\n      }\n      return model;\n    });\n    return Restangular.service('user');\n  });\n```\n\nbut can't figure out how to use it in a controller!\nI'd like to do something like:\n\n``` javascript\nangular.module('...')\n  .controller('...', function ($scope, User) {\n    User.getList().then(function (users) {\n      $scope.users = users;\n      angular.forEach(users, function (user) {\n        user.customers.getList();\n      });\n    });\n    $scope.addUserCustomerAssociation = function (user, customer) {\n       user.customers.post(customer.id);\n    };\n   $scope.removeUserCustomerAssociation = function (user, customer) {\n       user.customers.remove(customer.id);\n    };\n  });\n```\n"},"comment":{"url":"https://api.github.com/repos/mgonto/restangular/issues/comments/265938363","html_url":"https://github.com/mgonto/restangular/issues/1381#issuecomment-265938363","issue_url":"https://api.github.com/repos/mgonto/restangular/issues/1381","id":265938363,"user":{"login":"alexjose","id":194099,"avatar_url":"https://avatars.githubusercontent.com/u/194099?v=3","gravatar_id":"","url":"https://api.github.com/users/alexjose","html_url":"https://github.com/alexjose","followers_url":"https://api.github.com/users/alexjose/followers","following_url":"https://api.github.com/users/alexjose/following{/other_user}","gists_url":"https://api.github.com/users/alexjose/gists{/gist_id}","starred_url":"https://api.github.com/users/alexjose/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexjose/subscriptions","organizations_url":"https://api.github.com/users/alexjose/orgs","repos_url":"https://api.github.com/users/alexjose/repos","events_url":"https://api.github.com/users/alexjose/events{/privacy}","received_events_url":"https://api.github.com/users/alexjose/received_events","type":"User","site_admin":false},"created_at":"2016-12-09T05:41:31Z","updated_at":"2016-12-09T05:41:31Z","body":"I am also trying to figure this out.  How to build Nested decoupled services? "}}
{"actor":{"display_login":"alexjose"}}