{"action":"created","issue":{"url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/941","repository_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler","labels_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/941/labels{/name}","comments_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/941/comments","events_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/941/events","html_url":"https://github.com/strongloop/loopback-datasource-juggler/issues/941","id":156220890,"number":941,"title":"Is it possible to add conditions on \"through\" model in \"hasManyThrough\" relation?","user":{"login":"windyinwind","id":6670397,"avatar_url":"https://avatars.githubusercontent.com/u/6670397?v=3","gravatar_id":"","url":"https://api.github.com/users/windyinwind","html_url":"https://github.com/windyinwind","followers_url":"https://api.github.com/users/windyinwind/followers","following_url":"https://api.github.com/users/windyinwind/following{/other_user}","gists_url":"https://api.github.com/users/windyinwind/gists{/gist_id}","starred_url":"https://api.github.com/users/windyinwind/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/windyinwind/subscriptions","organizations_url":"https://api.github.com/users/windyinwind/orgs","repos_url":"https://api.github.com/users/windyinwind/repos","events_url":"https://api.github.com/users/windyinwind/events{/privacy}","received_events_url":"https://api.github.com/users/windyinwind/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/labels/feature","name":"feature","color":"bfe5bf"},{"url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/labels/hasManyThrough-relations","name":"hasManyThrough-relations","color":"eeeeee"},{"url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/labels/juggler-relations","name":"juggler-relations","color":"eeeeee"}],"state":"open","locked":false,"assignee":{"login":"0candy","id":14314570,"avatar_url":"https://avatars.githubusercontent.com/u/14314570?v=3","gravatar_id":"","url":"https://api.github.com/users/0candy","html_url":"https://github.com/0candy","followers_url":"https://api.github.com/users/0candy/followers","following_url":"https://api.github.com/users/0candy/following{/other_user}","gists_url":"https://api.github.com/users/0candy/gists{/gist_id}","starred_url":"https://api.github.com/users/0candy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/0candy/subscriptions","organizations_url":"https://api.github.com/users/0candy/orgs","repos_url":"https://api.github.com/users/0candy/repos","events_url":"https://api.github.com/users/0candy/events{/privacy}","received_events_url":"https://api.github.com/users/0candy/received_events","type":"User","site_admin":false},"assignees":[{"login":"0candy","id":14314570,"avatar_url":"https://avatars.githubusercontent.com/u/14314570?v=3","gravatar_id":"","url":"https://api.github.com/users/0candy","html_url":"https://github.com/0candy","followers_url":"https://api.github.com/users/0candy/followers","following_url":"https://api.github.com/users/0candy/following{/other_user}","gists_url":"https://api.github.com/users/0candy/gists{/gist_id}","starred_url":"https://api.github.com/users/0candy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/0candy/subscriptions","organizations_url":"https://api.github.com/users/0candy/orgs","repos_url":"https://api.github.com/users/0candy/repos","events_url":"https://api.github.com/users/0candy/events{/privacy}","received_events_url":"https://api.github.com/users/0candy/received_events","type":"User","site_admin":false}],"milestone":null,"comments":7,"created_at":"2016-05-23T08:00:46Z","updated_at":"2016-08-26T03:33:02Z","closed_at":null,"body":"I'm using mysql, relation of teachers and students is many-to-many.\r\nI want to select all students of one teacher, below is my table definition:\r\nTeacher table:\r\n\r\n\r\nid | name\r\n------------ | -------------\r\n1 | Tom\r\n2 | Jerry\r\n...| ...\r\n\r\nStudent table:\r\n\r\nid |  name\r\n------------ | -------------\r\n1 |  Sam\r\n2 |  Hank\r\n...| ...\r\n\r\nand relation table (teacher_student):\r\n\r\nteacher_id |  student_id | **deleted**\r\n------------ | ------------- |----------------\r\n1 |  1| 1\r\n2 |  2|  0\r\n...| ...|....\r\n\r\nThe **deleted** in relation representing if this relation is valid(1 stand for valid, and 0 stand for invalid).\r\n\r\nRelation definition in Teacher.json\r\n\r\n\"students\": {\r\n      \"type\": \"hasMany\",\r\n      \"model\": \"Student\",\r\n      \"foreignKey\": \"teacher_id\",\r\n      \"through\": \"teacher_student\"\r\n    },\r\n\r\n\r\nI want to select all valid students of one teacher.\r\n\r\nSo I use:\r\n```\r\nTeacher.findById(id, {\r\n      fields: {\r\n        id: true\r\n      },\r\n      include: {\r\n        relation: 'students',\r\n        where:  {deleted: false}  //  not filter invalid relations if add thin line \r\n        scope: {\r\n          where: {\r\n            deleted: 0\r\n          }\r\n        }\r\n      }, function(err, result){\r\n        // process result\r\n    }\r\n\r\n```\r\nSo is it possible to add conditions on teacher_student model? OR I have to manually filter those invalid relations.\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/comments/242620151","html_url":"https://github.com/strongloop/loopback-datasource-juggler/issues/941#issuecomment-242620151","issue_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/941","id":242620151,"user":{"login":"windyinwind","id":6670397,"avatar_url":"https://avatars.githubusercontent.com/u/6670397?v=3","gravatar_id":"","url":"https://api.github.com/users/windyinwind","html_url":"https://github.com/windyinwind","followers_url":"https://api.github.com/users/windyinwind/followers","following_url":"https://api.github.com/users/windyinwind/following{/other_user}","gists_url":"https://api.github.com/users/windyinwind/gists{/gist_id}","starred_url":"https://api.github.com/users/windyinwind/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/windyinwind/subscriptions","organizations_url":"https://api.github.com/users/windyinwind/orgs","repos_url":"https://api.github.com/users/windyinwind/repos","events_url":"https://api.github.com/users/windyinwind/events{/privacy}","received_events_url":"https://api.github.com/users/windyinwind/received_events","type":"User","site_admin":false},"created_at":"2016-08-26T03:33:02Z","updated_at":"2016-08-26T03:33:02Z","body":"@zbarbuto I tried your model definition and it works like a charm.　Though it's not a perfect solution, it still the best workaround I ever met. I will your solution till loopback support it officially. Thanks a lot."}}
{"actor":{"display_login":"windyinwind"}}