{"action":"created","issue":{"url":"https://api.github.com/repos/strongloop/loopback/issues/1441","repository_url":"https://api.github.com/repos/strongloop/loopback","labels_url":"https://api.github.com/repos/strongloop/loopback/issues/1441/labels{/name}","comments_url":"https://api.github.com/repos/strongloop/loopback/issues/1441/comments","events_url":"https://api.github.com/repos/strongloop/loopback/issues/1441/events","html_url":"https://github.com/strongloop/loopback/issues/1441","id":86588267,"number":1441,"title":"Seems there is no way to access Roles from User Object/API","user":{"login":"valllabh","id":1380940,"avatar_url":"https://avatars.githubusercontent.com/u/1380940?v=3","gravatar_id":"","url":"https://api.github.com/users/valllabh","html_url":"https://github.com/valllabh","followers_url":"https://api.github.com/users/valllabh/followers","following_url":"https://api.github.com/users/valllabh/following{/other_user}","gists_url":"https://api.github.com/users/valllabh/gists{/gist_id}","starred_url":"https://api.github.com/users/valllabh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/valllabh/subscriptions","organizations_url":"https://api.github.com/users/valllabh/orgs","repos_url":"https://api.github.com/users/valllabh/repos","events_url":"https://api.github.com/users/valllabh/events{/privacy}","received_events_url":"https://api.github.com/users/valllabh/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/strongloop/loopback/labels/triage","name":"triage","color":"eb6420"},{"url":"https://api.github.com/repos/strongloop/loopback/labels/waiting","name":"waiting","color":"eeeeee"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":22,"created_at":"2015-06-09T12:47:27Z","updated_at":"2016-02-04T09:05:33Z","closed_at":null,"body":"It seems there is no way to access `User` `Roles` in user query.\r\n\r\nI tried to create relation `roles` in `User`\r\n\r\n```\r\n\"relations\": {\r\n    \"roles\": {\r\n      \"type\": \"hasAndBelongsToMany\",\r\n      \"model\": \"Role\",\r\n      \"through\": \"RoleMapping\",\r\n      \"polymorphic\": \"principal\"\r\n    }\r\n}\r\n```\r\n\r\nadding roles to user `userObj.roles.add(roleObj)` works and create following entry in `RoleMapping`\r\n\r\n```\r\n{\r\n    \"_id\" : ObjectId(\"5576deca062655136bdb154c\"),\r\n    \"principalType\" : \"user\",\r\n    \"principalId\" : \"5576dec9062655136bdb154a\",\r\n    \"roleId\" : ObjectId(\"5576deca062655136bdb154b\")\r\n}\r\n```\r\n\r\nbut when I try to query in `user/{id}/roles` output comes blank/empty array. \r\nI also tried updating `\"principalType\" : \"user\"` to `\"principalType\" : \"USER\"` but nothing works.\r\n\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/strongloop/loopback/issues/comments/179719732","html_url":"https://github.com/strongloop/loopback/issues/1441#issuecomment-179719732","issue_url":"https://api.github.com/repos/strongloop/loopback/issues/1441","id":179719732,"user":{"login":"AurelieV","id":5425038,"avatar_url":"https://avatars.githubusercontent.com/u/5425038?v=3","gravatar_id":"","url":"https://api.github.com/users/AurelieV","html_url":"https://github.com/AurelieV","followers_url":"https://api.github.com/users/AurelieV/followers","following_url":"https://api.github.com/users/AurelieV/following{/other_user}","gists_url":"https://api.github.com/users/AurelieV/gists{/gist_id}","starred_url":"https://api.github.com/users/AurelieV/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AurelieV/subscriptions","organizations_url":"https://api.github.com/users/AurelieV/orgs","repos_url":"https://api.github.com/users/AurelieV/repos","events_url":"https://api.github.com/users/AurelieV/events{/privacy}","received_events_url":"https://api.github.com/users/AurelieV/received_events","type":"User","site_admin":false},"created_at":"2016-02-04T09:05:33Z","updated_at":"2016-02-04T09:05:33Z","body":"I will try this this morning, but this is not a permanent solution because we need to not be dependant of the database type. "}}