{"action":"created","issue":{"url":"https://api.github.com/repos/laravel/framework/issues/21731","repository_url":"https://api.github.com/repos/laravel/framework","labels_url":"https://api.github.com/repos/laravel/framework/issues/21731/labels{/name}","comments_url":"https://api.github.com/repos/laravel/framework/issues/21731/comments","events_url":"https://api.github.com/repos/laravel/framework/issues/21731/events","html_url":"https://github.com/laravel/framework/issues/21731","id":266557147,"number":21731,"title":"HasMany/HasOneOrMany Relations shouldn't add WHERE key IS NOT NULL to query","user":{"login":"ckdot","id":7283097,"avatar_url":"https://avatars2.githubusercontent.com/u/7283097?v=4","gravatar_id":"","url":"https://api.github.com/users/ckdot","html_url":"https://github.com/ckdot","followers_url":"https://api.github.com/users/ckdot/followers","following_url":"https://api.github.com/users/ckdot/following{/other_user}","gists_url":"https://api.github.com/users/ckdot/gists{/gist_id}","starred_url":"https://api.github.com/users/ckdot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ckdot/subscriptions","organizations_url":"https://api.github.com/users/ckdot/orgs","repos_url":"https://api.github.com/users/ckdot/repos","events_url":"https://api.github.com/users/ckdot/events{/privacy}","received_events_url":"https://api.github.com/users/ckdot/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-10-18T16:26:35Z","updated_at":"2017-10-18T17:09:36Z","closed_at":null,"author_association":"NONE","body":"- Laravel Version: 5.5.x\r\n- PHP Version: 5.6 - 7.1\r\n\r\n### Description:\r\nWhen defining a hasMany relationship to a model, the query to fetch the relation entities should not add a condition that the key must not be NULL.\r\n\r\n### Steps To Reproduce:\r\n1. Add a relation to your model, e.g.:\r\n\r\n    public function siblings()\r\n    {\r\n        return $this->hasMany(Type::class, 'parent_id', 'parent_id');\r\n    }\r\n\r\n2. Check executed queries when calling $model->siblings\r\n\r\nQuery will be e.g.:\r\n`select` * from `categories` where `categories`.`parent_id` = 5 and `categories`.`parent_id` is not null`\r\n\r\nThis is probably fine if you just have parent/child relations or similar but won't work for siblings like in the example, if you want to have all siblings of your root categories. The generated query would be:\r\n`select` * from `categories` where `categories`.`parent_id` IS NULL and `categories`.`parent_id` is not null`\r\n\r\nThis will return an empty result all the time and should is not expected behaviour.\r\n"},"comment":{"url":"https://api.github.com/repos/laravel/framework/issues/comments/337660747","html_url":"https://github.com/laravel/framework/issues/21731#issuecomment-337660747","issue_url":"https://api.github.com/repos/laravel/framework/issues/21731","id":337660747,"user":{"login":"Dylan-DPC","id":12371125,"avatar_url":"https://avatars1.githubusercontent.com/u/12371125?v=4","gravatar_id":"","url":"https://api.github.com/users/Dylan-DPC","html_url":"https://github.com/Dylan-DPC","followers_url":"https://api.github.com/users/Dylan-DPC/followers","following_url":"https://api.github.com/users/Dylan-DPC/following{/other_user}","gists_url":"https://api.github.com/users/Dylan-DPC/gists{/gist_id}","starred_url":"https://api.github.com/users/Dylan-DPC/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Dylan-DPC/subscriptions","organizations_url":"https://api.github.com/users/Dylan-DPC/orgs","repos_url":"https://api.github.com/users/Dylan-DPC/repos","events_url":"https://api.github.com/users/Dylan-DPC/events{/privacy}","received_events_url":"https://api.github.com/users/Dylan-DPC/received_events","type":"User","site_admin":false},"created_at":"2017-10-18T17:09:36Z","updated_at":"2017-10-18T17:09:36Z","author_association":"CONTRIBUTOR","body":"It makes no sense. If foreign key is null it means it is not related. Also if you eager load with `with`, it will return you all the columns with foreign key as null. I don't see this as a bug"}}
{"actor":{"display_login":"Dylan-DPC"}}