{"action":"created","issue":{"url":"https://api.github.com/repos/octobercms/october/issues/3976","repository_url":"https://api.github.com/repos/octobercms/october","labels_url":"https://api.github.com/repos/octobercms/october/issues/3976/labels{/name}","comments_url":"https://api.github.com/repos/octobercms/october/issues/3976/comments","events_url":"https://api.github.com/repos/octobercms/october/issues/3976/events","html_url":"https://github.com/octobercms/october/pull/3976","id":390013026,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM3ODczNjU5","number":3976,"title":"Don't error out if multiple rows found in a hasOne relation","user":{"login":"Flynsarmy","id":334808,"node_id":"MDQ6VXNlcjMzNDgwOA==","avatar_url":"https://avatars1.githubusercontent.com/u/334808?v=4","gravatar_id":"","url":"https://api.github.com/users/Flynsarmy","html_url":"https://github.com/Flynsarmy","followers_url":"https://api.github.com/users/Flynsarmy/followers","following_url":"https://api.github.com/users/Flynsarmy/following{/other_user}","gists_url":"https://api.github.com/users/Flynsarmy/gists{/gist_id}","starred_url":"https://api.github.com/users/Flynsarmy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Flynsarmy/subscriptions","organizations_url":"https://api.github.com/users/Flynsarmy/orgs","repos_url":"https://api.github.com/users/Flynsarmy/repos","events_url":"https://api.github.com/users/Flynsarmy/events{/privacy}","received_events_url":"https://api.github.com/users/Flynsarmy/received_events","type":"User","site_admin":false},"labels":[{"id":731859745,"node_id":"MDU6TGFiZWw3MzE4NTk3NDU=","url":"https://api.github.com/repos/octobercms/october/labels/Status:%20Response%20Needed","name":"Status: Response Needed","color":"b60205","default":false},{"id":143615025,"node_id":"MDU6TGFiZWwxNDM2MTUwMjU=","url":"https://api.github.com/repos/octobercms/october/labels/Type:%20Unconfirmed%20Bug","name":"Type: Unconfirmed Bug","color":"f7c6c7","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-12-12T00:25:57Z","updated_at":"2018-12-12T22:30:57Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/octobercms/october/pulls/3976","html_url":"https://github.com/octobercms/october/pull/3976","diff_url":"https://github.com/octobercms/october/pull/3976.diff","patch_url":"https://github.com/octobercms/october/pull/3976.patch"},"body":"## The Issue\r\n\r\nThe Lists widget will error out if you define a hasOne relation column but multiple related records are found in the database.\r\n\r\n## In Depth\r\nSay I have the following two tables:\r\n```\r\nfoo (\r\n  id\r\n  bar_id\r\n  name\r\n)\r\n\r\nbar (\r\n  id\r\n)\r\n```\r\nMy _Bar_ model defines a _hasOne_ relation to the _Foo_ model and my Bar List is displaying the relation like so:\r\n```yaml\r\nfoo:\r\n    label: Name\r\n    type: relation\r\n    relation: bar_id\r\n    select: name\r\n```\r\nThis will work perfectly fine unless the _foo_ table has multiple records with the same _bar_id_ in which case the Lists widget will generate the following SQL:\r\n\r\n```sql\r\nselect \r\n\t`bar`.*, \r\n\t(select name from `foo` where `bar`.`id` = `foo`.`bar_id`) as `name` \r\nfrom `bar` \r\norder by `id` desc\r\n```\r\nresulting in the SQL error:\r\n> Subquery returns more than 1 row\r\n\r\nThe list will fail to render with no visible error to the end user - it merely says no records found even if there are hundreds of records in the DB.\r\n\r\n## Solution\r\n\r\nThis PR just checks for a hasOne relation type and limits the subquery to the first result, fixing the SQL error by returning the first matching row. This PR is backwards compatible and will not break existing installations - in fact it may slightly improve efficiency on existing installations as the DB engine doesn't need to keep looking after it's found its first result."},"comment":{"url":"https://api.github.com/repos/octobercms/october/issues/comments/446769004","html_url":"https://github.com/octobercms/october/pull/3976#issuecomment-446769004","issue_url":"https://api.github.com/repos/octobercms/october/issues/3976","id":446769004,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0Njc2OTAwNA==","user":{"login":"LukeTowers","id":7253840,"node_id":"MDQ6VXNlcjcyNTM4NDA=","avatar_url":"https://avatars0.githubusercontent.com/u/7253840?v=4","gravatar_id":"","url":"https://api.github.com/users/LukeTowers","html_url":"https://github.com/LukeTowers","followers_url":"https://api.github.com/users/LukeTowers/followers","following_url":"https://api.github.com/users/LukeTowers/following{/other_user}","gists_url":"https://api.github.com/users/LukeTowers/gists{/gist_id}","starred_url":"https://api.github.com/users/LukeTowers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LukeTowers/subscriptions","organizations_url":"https://api.github.com/users/LukeTowers/orgs","repos_url":"https://api.github.com/users/LukeTowers/repos","events_url":"https://api.github.com/users/LukeTowers/events{/privacy}","received_events_url":"https://api.github.com/users/LukeTowers/received_events","type":"User","site_admin":false},"created_at":"2018-12-12T22:30:57Z","updated_at":"2018-12-12T22:30:57Z","author_association":"MEMBER","body":"@Flynsarmy I meant that the validation would occur on your end within your plugin 😉 "}}
{"actor":{"display_login":"LukeTowers"}}