{"action":"created","issue":{"url":"https://api.github.com/repos/strongloop/loopback/issues/1859","labels_url":"https://api.github.com/repos/strongloop/loopback/issues/1859/labels{/name}","comments_url":"https://api.github.com/repos/strongloop/loopback/issues/1859/comments","events_url":"https://api.github.com/repos/strongloop/loopback/issues/1859/events","html_url":"https://github.com/strongloop/loopback/issues/1859","id":120531267,"number":1859,"title":"Scopes in model relations - strongloop api","user":{"login":"J0N47H4N","id":5219189,"avatar_url":"https://avatars.githubusercontent.com/u/5219189?v=3","gravatar_id":"","url":"https://api.github.com/users/J0N47H4N","html_url":"https://github.com/J0N47H4N","followers_url":"https://api.github.com/users/J0N47H4N/followers","following_url":"https://api.github.com/users/J0N47H4N/following{/other_user}","gists_url":"https://api.github.com/users/J0N47H4N/gists{/gist_id}","starred_url":"https://api.github.com/users/J0N47H4N/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/J0N47H4N/subscriptions","organizations_url":"https://api.github.com/users/J0N47H4N/orgs","repos_url":"https://api.github.com/users/J0N47H4N/repos","events_url":"https://api.github.com/users/J0N47H4N/events{/privacy}","received_events_url":"https://api.github.com/users/J0N47H4N/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/strongloop/loopback/labels/feature","name":"feature","color":"009800"},{"url":"https://api.github.com/repos/strongloop/loopback/labels/triage","name":"triage","color":"eb6420"}],"state":"open","locked":false,"assignee":{"login":"jannyHou","id":12554153,"avatar_url":"https://avatars.githubusercontent.com/u/12554153?v=3","gravatar_id":"","url":"https://api.github.com/users/jannyHou","html_url":"https://github.com/jannyHou","followers_url":"https://api.github.com/users/jannyHou/followers","following_url":"https://api.github.com/users/jannyHou/following{/other_user}","gists_url":"https://api.github.com/users/jannyHou/gists{/gist_id}","starred_url":"https://api.github.com/users/jannyHou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jannyHou/subscriptions","organizations_url":"https://api.github.com/users/jannyHou/orgs","repos_url":"https://api.github.com/users/jannyHou/repos","events_url":"https://api.github.com/users/jannyHou/events{/privacy}","received_events_url":"https://api.github.com/users/jannyHou/received_events","type":"User","site_admin":false},"milestone":null,"comments":10,"created_at":"2015-12-05T05:35:11Z","updated_at":"2015-12-08T22:25:18Z","closed_at":null,"body":"I found in the documentation that [scopes][1] enable you to specify commonly-used queries that you can reference as method calls on a model. Below i have a `category` model. I am trying to create scopes that apply to the relation. Unfortunately the below does nothing. How can I get scopes to apply to relation as shown below?\r\n\r\n`GET /Categories/{id}/games` - This gets all games \r\n\r\nI tried to modify the model: *common/models/category.json*\r\n\r\n    \"relations\": {\r\n        \"categories\": {\r\n          \"type\": \"hasMany\",\r\n          \"model\": \"Categories\",\r\n          \"foreignKey\": \"\",\r\n          \"scopes\": {\r\n            \"mature\": {\"where\": {\"mature\": true}},\r\n    \t\t\"sports\": {\"where\": {\"sports\": true}},\r\n          }\r\n        }\r\n    },\r\n\r\nI want to be able to get the data through endpoing: `/Categories/{id}/games/mature`\r\n\r\nTable schema:\r\n\r\n    catgories\r\n    \r\n    category_name\t\tcategory_id \r\n    -------------\t\t-----------\r\n    fighting\t\t\t1001\r\n    racing\t\t\t\t1002\r\n    sports\t\t\t\t1003\r\n    \r\n    games\r\n    \r\n    game_name\t\t\tcategory_id\t\tmature\r\n    ------------\t\t-----------\t\t--------------\r\n    Tekken\t\t\t\t10001\t\t\ttrue\r\n    Forza\t\t\t\t10002\t\t\tfalse\r\n\r\n\r\n  [1]: https://docs.strongloop.com/display/public/LB/Model+definition+JSON+file#ModeldefinitionJSONfile-Scopes"},"comment":{"url":"https://api.github.com/repos/strongloop/loopback/issues/comments/163037446","html_url":"https://github.com/strongloop/loopback/issues/1859#issuecomment-163037446","issue_url":"https://api.github.com/repos/strongloop/loopback/issues/1859","id":163037446,"user":{"login":"J0N47H4N","id":5219189,"avatar_url":"https://avatars.githubusercontent.com/u/5219189?v=3","gravatar_id":"","url":"https://api.github.com/users/J0N47H4N","html_url":"https://github.com/J0N47H4N","followers_url":"https://api.github.com/users/J0N47H4N/followers","following_url":"https://api.github.com/users/J0N47H4N/following{/other_user}","gists_url":"https://api.github.com/users/J0N47H4N/gists{/gist_id}","starred_url":"https://api.github.com/users/J0N47H4N/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/J0N47H4N/subscriptions","organizations_url":"https://api.github.com/users/J0N47H4N/orgs","repos_url":"https://api.github.com/users/J0N47H4N/repos","events_url":"https://api.github.com/users/J0N47H4N/events{/privacy}","received_events_url":"https://api.github.com/users/J0N47H4N/received_events","type":"User","site_admin":false},"created_at":"2015-12-08T22:25:18Z","updated_at":"2015-12-08T22:25:18Z","body":"Thanks @amenadiel close to what I want. For anyone trying to achieve the same goal,  currently it can only be done using Remote Methods as mentioned above. \r\n\r\nAdded the remote methods to `common/models/category.js`\r\n\r\n```\r\nmodule.exports = function(Category) {\r\n\r\n    Category.mature = function(id, callback) {\r\n        var app = this.app;\r\n        var Game = app.models.Game;\r\n        Game.find({\r\n            \"where\": {\r\n                categoryId: id,\r\n                mature: true\r\n            }\r\n        }, function(err, gameArr) {\r\n            if (err) return callback(err);\r\n            console.log(gameArr);\r\n            callback(null, gameArr);\r\n        });\r\n    }\r\n\r\n    Category.remoteMethod(\r\n        'mature', {\r\n            accepts: [{\r\n                arg: 'id',\r\n                type: 'number',\r\n                required: true\r\n            }],\r\n            // mixing ':id' into the rest url allows $owner to be determined and used for access control\r\n            http: {\r\n                path: '/:id/games/mature',\r\n                verb: 'get'\r\n            },\r\n            returns: {\r\n                arg: 'games',\r\n                type: 'array'\r\n            }\r\n        }\r\n    );\r\n\r\n};\r\n\r\n```\r\nAdd the ACL property `common/models/category.json`.\r\n\r\n```\r\n.....\r\n.....\r\n\"acls\": [\r\n  {\r\n     \"principalType\": \"ROLE\",\r\n     \"principalId\": \"$everyone\",\r\n     \"permission\": \"ALLOW\",\r\n     \"property\": \"mature\"\r\n  }\r\n] \r\n```\r\nNow I am able to get all games that are `mature` by get method: http://0.0.0.0:3000/api/categories/:id/games/mature"}}