{"action":"created","issue":{"url":"https://api.github.com/repos/staudenmeir/eloquent-has-many-deep/issues/3","repository_url":"https://api.github.com/repos/staudenmeir/eloquent-has-many-deep","labels_url":"https://api.github.com/repos/staudenmeir/eloquent-has-many-deep/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/staudenmeir/eloquent-has-many-deep/issues/3/comments","events_url":"https://api.github.com/repos/staudenmeir/eloquent-has-many-deep/issues/3/events","html_url":"https://github.com/staudenmeir/eloquent-has-many-deep/issues/3","id":348854582,"node_id":"MDU6SXNzdWUzNDg4NTQ1ODI=","number":3,"title":"Query hasManyDeep","user":{"login":"JoeDawson","id":1009696,"node_id":"MDQ6VXNlcjEwMDk2OTY=","avatar_url":"https://avatars2.githubusercontent.com/u/1009696?v=4","gravatar_id":"","url":"https://api.github.com/users/JoeDawson","html_url":"https://github.com/JoeDawson","followers_url":"https://api.github.com/users/JoeDawson/followers","following_url":"https://api.github.com/users/JoeDawson/following{/other_user}","gists_url":"https://api.github.com/users/JoeDawson/gists{/gist_id}","starred_url":"https://api.github.com/users/JoeDawson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoeDawson/subscriptions","organizations_url":"https://api.github.com/users/JoeDawson/orgs","repos_url":"https://api.github.com/users/JoeDawson/repos","events_url":"https://api.github.com/users/JoeDawson/events{/privacy}","received_events_url":"https://api.github.com/users/JoeDawson/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-08-08T19:09:49Z","updated_at":"2018-08-08T20:33:42Z","closed_at":null,"author_association":"NONE","body":"Hello, me again... (sorry!)\r\n\r\nI currently have have the following relation setup on my `Collective` model (as per #2)\r\n\r\n```php\r\npublic function videos()\r\n{\r\n    return $this->hasManyDeep(Video::class, [Artist::class, 'artist_video'])->groupBy('videos.id');\r\n}\r\n```\r\n\r\nHow can I query this relation? I'm currently trying the following:\r\n\r\n```php\r\n$collective->videos()->where('slug', 'my-slug')->first();\r\n```\r\n\r\nHowever I'm receiving the following error:\r\n\r\n> Integrity constraint violation: 1052 Column 'slug' in where clause is ambiguous (SQL: select `videos`.*, `artists`.`collective_id` from `videos` inner join `artist_video` on `artist_video`.`video_id` = `videos`.`id` inner join `artists` on `artists`.`id` = `artist_video`.`artist_id` where `artists`.`collective_id` = 1 and `slug` = my-slug group by `videos`.`id` limit 1)\r\n\r\nAny ideas how I can get this to work?\r\n\r\nThanks in advance!"},"comment":{"url":"https://api.github.com/repos/staudenmeir/eloquent-has-many-deep/issues/comments/411542890","html_url":"https://github.com/staudenmeir/eloquent-has-many-deep/issues/3#issuecomment-411542890","issue_url":"https://api.github.com/repos/staudenmeir/eloquent-has-many-deep/issues/3","id":411542890,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMTU0Mjg5MA==","user":{"login":"JoeDawson","id":1009696,"node_id":"MDQ6VXNlcjEwMDk2OTY=","avatar_url":"https://avatars2.githubusercontent.com/u/1009696?v=4","gravatar_id":"","url":"https://api.github.com/users/JoeDawson","html_url":"https://github.com/JoeDawson","followers_url":"https://api.github.com/users/JoeDawson/followers","following_url":"https://api.github.com/users/JoeDawson/following{/other_user}","gists_url":"https://api.github.com/users/JoeDawson/gists{/gist_id}","starred_url":"https://api.github.com/users/JoeDawson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoeDawson/subscriptions","organizations_url":"https://api.github.com/users/JoeDawson/orgs","repos_url":"https://api.github.com/users/JoeDawson/repos","events_url":"https://api.github.com/users/JoeDawson/events{/privacy}","received_events_url":"https://api.github.com/users/JoeDawson/received_events","type":"User","site_admin":false},"created_at":"2018-08-08T20:33:42Z","updated_at":"2018-08-08T20:33:42Z","author_association":"NONE","body":"Sorry I might have confused it by raising #2 in conversation.\r\n\r\nThe reason for `$collective->videos()->where('slug', 'my-slug')->first();` is because I am using route model binding and want to ensure that when someone visits the following route, the video belongs to a collective.\r\n\r\n```php\r\n/collectives/{collective}/videos/{video}\r\n```\r\n\r\nThen my route model binding looks like this - you can ignore the artist/channel code, I just left it here so you have a little bit more of an understanding of my application;\r\n\r\n```php\r\nRoute::bind('video', function($value, $route)\r\n{\r\n    if(array_key_exists('artist', $route->parameters())) {\r\n        return $route->artist->videos()->where('slug', $value)->first();\r\n    }\r\n\r\n    if(array_key_exists('channel', $route->parameters())) {\r\n        return $route->channel->videos()->where('slug', $value)->first();\r\n    }\r\n\r\n    if(array_key_exists('collective', $route->parameters())) {\r\n        return $route->collective->videos()->where('slug', $value)->first();\r\n    }\r\n\r\n    return \\App\\Video::where('slug', $value)->first();\r\n});\r\n```\r\n\r\nI need the `->groupBy()` so that when you visit a collective in my application, you don't see duplicate videos.\r\n\r\nHope that's a little clearer?"}}
{"actor":{"display_login":"JoeDawson"}}