{"action":"created","issue":{"url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/1402","repository_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler","labels_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/1402/labels{/name}","comments_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/1402/comments","events_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/1402/events","html_url":"https://github.com/strongloop/loopback-datasource-juggler/issues/1402","id":234317746,"number":1402,"title":"When using a non-id column in many-to-many relationship, only the last result is populated correctly","user":{"login":"dazwin","id":4027649,"avatar_url":"https://avatars3.githubusercontent.com/u/4027649?v=4","gravatar_id":"","url":"https://api.github.com/users/dazwin","html_url":"https://github.com/dazwin","followers_url":"https://api.github.com/users/dazwin/followers","following_url":"https://api.github.com/users/dazwin/following{/other_user}","gists_url":"https://api.github.com/users/dazwin/gists{/gist_id}","starred_url":"https://api.github.com/users/dazwin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dazwin/subscriptions","organizations_url":"https://api.github.com/users/dazwin/orgs","repos_url":"https://api.github.com/users/dazwin/repos","events_url":"https://api.github.com/users/dazwin/events{/privacy}","received_events_url":"https://api.github.com/users/dazwin/received_events","type":"User","site_admin":false},"labels":[{"id":674211002,"url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/labels/stale","name":"stale","color":"a3af67","default":false},{"id":640670920,"url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/labels/team-apex","name":"team-apex","color":"fef2c0","default":false},{"id":173721300,"url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/labels/triaging","name":"triaging","color":"fef2c0","default":false}],"state":"open","locked":false,"assignee":{"login":"b-admike","id":13950637,"avatar_url":"https://avatars3.githubusercontent.com/u/13950637?v=4","gravatar_id":"","url":"https://api.github.com/users/b-admike","html_url":"https://github.com/b-admike","followers_url":"https://api.github.com/users/b-admike/followers","following_url":"https://api.github.com/users/b-admike/following{/other_user}","gists_url":"https://api.github.com/users/b-admike/gists{/gist_id}","starred_url":"https://api.github.com/users/b-admike/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/b-admike/subscriptions","organizations_url":"https://api.github.com/users/b-admike/orgs","repos_url":"https://api.github.com/users/b-admike/repos","events_url":"https://api.github.com/users/b-admike/events{/privacy}","received_events_url":"https://api.github.com/users/b-admike/received_events","type":"User","site_admin":false},"assignees":[{"login":"b-admike","id":13950637,"avatar_url":"https://avatars3.githubusercontent.com/u/13950637?v=4","gravatar_id":"","url":"https://api.github.com/users/b-admike","html_url":"https://github.com/b-admike","followers_url":"https://api.github.com/users/b-admike/followers","following_url":"https://api.github.com/users/b-admike/following{/other_user}","gists_url":"https://api.github.com/users/b-admike/gists{/gist_id}","starred_url":"https://api.github.com/users/b-admike/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/b-admike/subscriptions","organizations_url":"https://api.github.com/users/b-admike/orgs","repos_url":"https://api.github.com/users/b-admike/repos","events_url":"https://api.github.com/users/b-admike/events{/privacy}","received_events_url":"https://api.github.com/users/b-admike/received_events","type":"User","site_admin":false}],"milestone":null,"comments":2,"created_at":"2017-06-07T19:31:28Z","updated_at":"2017-10-13T14:45:07Z","closed_at":null,"author_association":"NONE","body":"# Description/Steps to reproduce\r\n\r\nIf a non-id field is used as the foreign key of a many-to-many relationship, when retrieving the relationship, only the last result is populated with matching items.\r\n\r\nThe example below includes the following models:\r\n- Foo, Bar, and a many-to-many join table to link them, FooBar\r\n- Widgets are owned by a Foo and define their relationship to Bar (via FooBar)\r\n\r\n$ git clone -b missing-relations-except-last https://github.com/dazwin/loopback-sandbox.git\r\n$ cd loopback-sandbox && npm install\r\n$ node loopback-sandbox &\r\n$ curl -s http://localhost:3000/api/Widgets | jq\r\n\r\n# Actual result\r\n```[\r\n  {\r\n    \"id\": \"3\",\r\n    \"fooId\": \"1\",\r\n    \"name\": \"widget3\",\r\n    \"bars\": []\r\n  },\r\n  {\r\n    \"id\": \"4\",\r\n    \"fooId\": \"1\",\r\n    \"name\": \"widget4\",\r\n    \"bars\": [\r\n      {\r\n        \"id\": \"2\",\r\n        \"name\": \"foo1\"\r\n      }\r\n    ]\r\n  }\r\n]\r\n```\r\n\r\n# Expected result\r\n```[\r\n  {\r\n    \"id\": \"3\",\r\n    \"fooId\": \"1\",\r\n    \"name\": \"widget3\",\r\n    \"bars\": [\r\n      {\r\n        \"id\": \"2\",\r\n        \"name\": \"foo1\"\r\n      }\r\n    ]\r\n  },\r\n  {\r\n    \"id\": \"4\",\r\n    \"fooId\": \"1\",\r\n    \"name\": \"widget4\",\r\n    \"bars\": [\r\n      {\r\n        \"id\": \"2\",\r\n        \"name\": \"foo1\"\r\n      }\r\n    ]\r\n  }\r\n]\r\n```\r\n\r\n# Additional information\r\n\r\nMy use case is that I'm using a 'loaded' hook on the model to perform some access control checks, where the same problem exists. Because 'loaded' is called for each result, and the related rows are only returned for the last result, there is no way to distinguish between the valid/last result and a result that simply does not have any associated relations.\r\n\r\nnode -e 'console.log(process.platform, process.arch, process.versions.node)'\r\n```\r\ndarwin x64 6.2.0\r\n```\r\n\r\nnpm ls --prod --depth 0 | grep loopback\r\n```\r\nloopback-sandbox@1.0.0 /Users/darrenw/Projects/loopback-sandbox\r\n├── loopback@2.38.3\r\n├── loopback-boot@2.24.0\r\n├── loopback-component-explorer@2.7.0\r\n├── loopback-datasource-juggler@2.54.1\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/comments/336473791","html_url":"https://github.com/strongloop/loopback-datasource-juggler/issues/1402#issuecomment-336473791","issue_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/1402","id":336473791,"user":{"login":"stale[bot]","id":26384082,"avatar_url":"https://avatars2.githubusercontent.com/u/26350515?v=4","gravatar_id":"","url":"https://api.github.com/users/stale%5Bbot%5D","html_url":"https://github.com/apps/stale","followers_url":"https://api.github.com/users/stale%5Bbot%5D/followers","following_url":"https://api.github.com/users/stale%5Bbot%5D/following{/other_user}","gists_url":"https://api.github.com/users/stale%5Bbot%5D/gists{/gist_id}","starred_url":"https://api.github.com/users/stale%5Bbot%5D/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stale%5Bbot%5D/subscriptions","organizations_url":"https://api.github.com/users/stale%5Bbot%5D/orgs","repos_url":"https://api.github.com/users/stale%5Bbot%5D/repos","events_url":"https://api.github.com/users/stale%5Bbot%5D/events{/privacy}","received_events_url":"https://api.github.com/users/stale%5Bbot%5D/received_events","type":"Bot","site_admin":false},"created_at":"2017-10-13T14:45:06Z","updated_at":"2017-10-13T14:45:06Z","author_association":"NONE","body":"This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the `CODEOWNERS` file at the top-level of this repository.\n"}}
{"actor":{"display_login":"stale"}}