{"action":"closed","number":24096,"pull_request":{"url":"https://api.github.com/repos/laravel/framework/pulls/24096","id":185721798,"html_url":"https://github.com/laravel/framework/pull/24096","diff_url":"https://github.com/laravel/framework/pull/24096.diff","patch_url":"https://github.com/laravel/framework/pull/24096.patch","issue_url":"https://api.github.com/repos/laravel/framework/issues/24096","number":24096,"state":"closed","locked":false,"title":"[5.6] Fix for HasManyThrough returning incorrect results with chunk()…","user":{"login":"iceheat","id":8448442,"avatar_url":"https://avatars0.githubusercontent.com/u/8448442?v=4","gravatar_id":"","url":"https://api.github.com/users/iceheat","html_url":"https://github.com/iceheat","followers_url":"https://api.github.com/users/iceheat/followers","following_url":"https://api.github.com/users/iceheat/following{/other_user}","gists_url":"https://api.github.com/users/iceheat/gists{/gist_id}","starred_url":"https://api.github.com/users/iceheat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iceheat/subscriptions","organizations_url":"https://api.github.com/users/iceheat/orgs","repos_url":"https://api.github.com/users/iceheat/repos","events_url":"https://api.github.com/users/iceheat/events{/privacy}","received_events_url":"https://api.github.com/users/iceheat/received_events","type":"User","site_admin":false},"body":"Laravel Version: 5.6.17\r\nPHP Version: 7.1.3 (MacOS 10.13.4)\r\n\r\n## Description:\r\n**Summary:** \r\nThis is pull request addresses the issues reported on #21774. Using the `chunk()` method on a `HasManyThrough` relation object returns incorrect results. This is due to to the fact that Eloquent QueryBuilder attempts to hydrate the the related model with intermediate model attributes. \r\n\r\n> When querying models through a hasManyThrough relationship and using chunk() on the query, all the retrieved models have the same id (and probably a non-existent id for the model), even though their other attributes have the correct values. It creates a problem when eager loading other relations, since they all have the same id.\r\nThe aforementioned issue  is a resulted because the intermediate model id is inserted on the query instead of the related model.\r\n\r\nWith the current codebase `get()` method has fixes the issue by getting an instance of the builder with the correct table and columns selected to overcome the issue. This can be demonstrated by the different model structure that would be retrieved when running\r\n`$country->posts()->get()` vs `$country->posts()->getQuery()->get()`\r\n\r\nThe same issue is manifested when using `each()` method. This is because `each()` uses the underlying `chunk()` method during its runtime. \r\n\r\n## Proposed fix\r\n`chunk()` and `each()` methods were added to `HasManyThrough` class to correct the selection of columns before they operate. This would contain the behaviour change to `HasManyThrough` without affecting any other behaviours.  Hence, there are no breaking changes introduced.\r\n\r\n### Tests\r\nAdded two extra tests to `DatabaseEloquentHasManyThroughIntegrationTest` to test `chunk()` and `each()`, where the models are checked to have the correct columns defined. \r\n","created_at":"2018-05-03T13:47:07Z","updated_at":"2018-05-03T13:53:36Z","closed_at":"2018-05-03T13:53:36Z","merged_at":"2018-05-03T13:53:35Z","merge_commit_sha":"48f07be5ec2ea1e6fd9d9f83be19e0f6fa1a021a","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/laravel/framework/pulls/24096/commits","review_comments_url":"https://api.github.com/repos/laravel/framework/pulls/24096/comments","review_comment_url":"https://api.github.com/repos/laravel/framework/pulls/comments{/number}","comments_url":"https://api.github.com/repos/laravel/framework/issues/24096/comments","statuses_url":"https://api.github.com/repos/laravel/framework/statuses/48f07be5ec2ea1e6fd9d9f83be19e0f6fa1a021a","head":{"label":"iceheat:5.6","ref":"5.6","sha":"48f07be5ec2ea1e6fd9d9f83be19e0f6fa1a021a","user":{"login":"iceheat","id":8448442,"avatar_url":"https://avatars0.githubusercontent.com/u/8448442?v=4","gravatar_id":"","url":"https://api.github.com/users/iceheat","html_url":"https://github.com/iceheat","followers_url":"https://api.github.com/users/iceheat/followers","following_url":"https://api.github.com/users/iceheat/following{/other_user}","gists_url":"https://api.github.com/users/iceheat/gists{/gist_id}","starred_url":"https://api.github.com/users/iceheat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iceheat/subscriptions","organizations_url":"https://api.github.com/users/iceheat/orgs","repos_url":"https://api.github.com/users/iceheat/repos","events_url":"https://api.github.com/users/iceheat/events{/privacy}","received_events_url":"https://api.github.com/users/iceheat/received_events","type":"User","site_admin":false},"repo":{"id":129921124,"name":"framework","full_name":"iceheat/framework","owner":{"login":"iceheat","id":8448442,"avatar_url":"https://avatars0.githubusercontent.com/u/8448442?v=4","gravatar_id":"","url":"https://api.github.com/users/iceheat","html_url":"https://github.com/iceheat","followers_url":"https://api.github.com/users/iceheat/followers","following_url":"https://api.github.com/users/iceheat/following{/other_user}","gists_url":"https://api.github.com/users/iceheat/gists{/gist_id}","starred_url":"https://api.github.com/users/iceheat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iceheat/subscriptions","organizations_url":"https://api.github.com/users/iceheat/orgs","repos_url":"https://api.github.com/users/iceheat/repos","events_url":"https://api.github.com/users/iceheat/events{/privacy}","received_events_url":"https://api.github.com/users/iceheat/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/iceheat/framework","description":null,"fork":true,"url":"https://api.github.com/repos/iceheat/framework","forks_url":"https://api.github.com/repos/iceheat/framework/forks","keys_url":"https://api.github.com/repos/iceheat/framework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/iceheat/framework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/iceheat/framework/teams","hooks_url":"https://api.github.com/repos/iceheat/framework/hooks","issue_events_url":"https://api.github.com/repos/iceheat/framework/issues/events{/number}","events_url":"https://api.github.com/repos/iceheat/framework/events","assignees_url":"https://api.github.com/repos/iceheat/framework/assignees{/user}","branches_url":"https://api.github.com/repos/iceheat/framework/branches{/branch}","tags_url":"https://api.github.com/repos/iceheat/framework/tags","blobs_url":"https://api.github.com/repos/iceheat/framework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/iceheat/framework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/iceheat/framework/git/refs{/sha}","trees_url":"https://api.github.com/repos/iceheat/framework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/iceheat/framework/statuses/{sha}","languages_url":"https://api.github.com/repos/iceheat/framework/languages","stargazers_url":"https://api.github.com/repos/iceheat/framework/stargazers","contributors_url":"https://api.github.com/repos/iceheat/framework/contributors","subscribers_url":"https://api.github.com/repos/iceheat/framework/subscribers","subscription_url":"https://api.github.com/repos/iceheat/framework/subscription","commits_url":"https://api.github.com/repos/iceheat/framework/commits{/sha}","git_commits_url":"https://api.github.com/repos/iceheat/framework/git/commits{/sha}","comments_url":"https://api.github.com/repos/iceheat/framework/comments{/number}","issue_comment_url":"https://api.github.com/repos/iceheat/framework/issues/comments{/number}","contents_url":"https://api.github.com/repos/iceheat/framework/contents/{+path}","compare_url":"https://api.github.com/repos/iceheat/framework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/iceheat/framework/merges","archive_url":"https://api.github.com/repos/iceheat/framework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/iceheat/framework/downloads","issues_url":"https://api.github.com/repos/iceheat/framework/issues{/number}","pulls_url":"https://api.github.com/repos/iceheat/framework/pulls{/number}","milestones_url":"https://api.github.com/repos/iceheat/framework/milestones{/number}","notifications_url":"https://api.github.com/repos/iceheat/framework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/iceheat/framework/labels{/name}","releases_url":"https://api.github.com/repos/iceheat/framework/releases{/id}","deployments_url":"https://api.github.com/repos/iceheat/framework/deployments","created_at":"2018-04-17T14:56:08Z","updated_at":"2018-05-03T13:46:12Z","pushed_at":"2018-05-03T13:46:08Z","git_url":"git://github.com/iceheat/framework.git","ssh_url":"git@github.com:iceheat/framework.git","clone_url":"https://github.com/iceheat/framework.git","svn_url":"https://github.com/iceheat/framework","homepage":"http://laravel.com","size":33326,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"5.6"}},"base":{"label":"laravel:5.6","ref":"5.6","sha":"5e91cc382c12654dca7174264860d51aad0fed38","user":{"login":"laravel","id":958072,"avatar_url":"https://avatars3.githubusercontent.com/u/958072?v=4","gravatar_id":"","url":"https://api.github.com/users/laravel","html_url":"https://github.com/laravel","followers_url":"https://api.github.com/users/laravel/followers","following_url":"https://api.github.com/users/laravel/following{/other_user}","gists_url":"https://api.github.com/users/laravel/gists{/gist_id}","starred_url":"https://api.github.com/users/laravel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/laravel/subscriptions","organizations_url":"https://api.github.com/users/laravel/orgs","repos_url":"https://api.github.com/users/laravel/repos","events_url":"https://api.github.com/users/laravel/events{/privacy}","received_events_url":"https://api.github.com/users/laravel/received_events","type":"Organization","site_admin":false},"repo":{"id":7548986,"name":"framework","full_name":"laravel/framework","owner":{"login":"laravel","id":958072,"avatar_url":"https://avatars3.githubusercontent.com/u/958072?v=4","gravatar_id":"","url":"https://api.github.com/users/laravel","html_url":"https://github.com/laravel","followers_url":"https://api.github.com/users/laravel/followers","following_url":"https://api.github.com/users/laravel/following{/other_user}","gists_url":"https://api.github.com/users/laravel/gists{/gist_id}","starred_url":"https://api.github.com/users/laravel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/laravel/subscriptions","organizations_url":"https://api.github.com/users/laravel/orgs","repos_url":"https://api.github.com/users/laravel/repos","events_url":"https://api.github.com/users/laravel/events{/privacy}","received_events_url":"https://api.github.com/users/laravel/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/laravel/framework","description":null,"fork":false,"url":"https://api.github.com/repos/laravel/framework","forks_url":"https://api.github.com/repos/laravel/framework/forks","keys_url":"https://api.github.com/repos/laravel/framework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/laravel/framework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/laravel/framework/teams","hooks_url":"https://api.github.com/repos/laravel/framework/hooks","issue_events_url":"https://api.github.com/repos/laravel/framework/issues/events{/number}","events_url":"https://api.github.com/repos/laravel/framework/events","assignees_url":"https://api.github.com/repos/laravel/framework/assignees{/user}","branches_url":"https://api.github.com/repos/laravel/framework/branches{/branch}","tags_url":"https://api.github.com/repos/laravel/framework/tags","blobs_url":"https://api.github.com/repos/laravel/framework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/laravel/framework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/laravel/framework/git/refs{/sha}","trees_url":"https://api.github.com/repos/laravel/framework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/laravel/framework/statuses/{sha}","languages_url":"https://api.github.com/repos/laravel/framework/languages","stargazers_url":"https://api.github.com/repos/laravel/framework/stargazers","contributors_url":"https://api.github.com/repos/laravel/framework/contributors","subscribers_url":"https://api.github.com/repos/laravel/framework/subscribers","subscription_url":"https://api.github.com/repos/laravel/framework/subscription","commits_url":"https://api.github.com/repos/laravel/framework/commits{/sha}","git_commits_url":"https://api.github.com/repos/laravel/framework/git/commits{/sha}","comments_url":"https://api.github.com/repos/laravel/framework/comments{/number}","issue_comment_url":"https://api.github.com/repos/laravel/framework/issues/comments{/number}","contents_url":"https://api.github.com/repos/laravel/framework/contents/{+path}","compare_url":"https://api.github.com/repos/laravel/framework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/laravel/framework/merges","archive_url":"https://api.github.com/repos/laravel/framework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/laravel/framework/downloads","issues_url":"https://api.github.com/repos/laravel/framework/issues{/number}","pulls_url":"https://api.github.com/repos/laravel/framework/pulls{/number}","milestones_url":"https://api.github.com/repos/laravel/framework/milestones{/number}","notifications_url":"https://api.github.com/repos/laravel/framework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/laravel/framework/labels{/name}","releases_url":"https://api.github.com/repos/laravel/framework/releases{/id}","deployments_url":"https://api.github.com/repos/laravel/framework/deployments","created_at":"2013-01-10T21:27:28Z","updated_at":"2018-05-03T13:44:29Z","pushed_at":"2018-05-03T13:53:34Z","git_url":"git://github.com/laravel/framework.git","ssh_url":"git@github.com:laravel/framework.git","clone_url":"https://github.com/laravel/framework.git","svn_url":"https://github.com/laravel/framework","homepage":"http://laravel.com","size":33435,"stargazers_count":12068,"watchers_count":12068,"language":"PHP","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5368,"mirror_url":null,"archived":false,"open_issues_count":161,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":5368,"open_issues":161,"watchers":12068,"default_branch":"5.6"}},"_links":{"self":{"href":"https://api.github.com/repos/laravel/framework/pulls/24096"},"html":{"href":"https://github.com/laravel/framework/pull/24096"},"issue":{"href":"https://api.github.com/repos/laravel/framework/issues/24096"},"comments":{"href":"https://api.github.com/repos/laravel/framework/issues/24096/comments"},"review_comments":{"href":"https://api.github.com/repos/laravel/framework/pulls/24096/comments"},"review_comment":{"href":"https://api.github.com/repos/laravel/framework/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/laravel/framework/pulls/24096/commits"},"statuses":{"href":"https://api.github.com/repos/laravel/framework/statuses/48f07be5ec2ea1e6fd9d9f83be19e0f6fa1a021a"}},"author_association":"NONE","merged":true,"mergeable":null,"rebaseable":null,"mergeable_state":"unknown","merged_by":{"login":"taylorotwell","id":463230,"avatar_url":"https://avatars3.githubusercontent.com/u/463230?v=4","gravatar_id":"","url":"https://api.github.com/users/taylorotwell","html_url":"https://github.com/taylorotwell","followers_url":"https://api.github.com/users/taylorotwell/followers","following_url":"https://api.github.com/users/taylorotwell/following{/other_user}","gists_url":"https://api.github.com/users/taylorotwell/gists{/gist_id}","starred_url":"https://api.github.com/users/taylorotwell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/taylorotwell/subscriptions","organizations_url":"https://api.github.com/users/taylorotwell/orgs","repos_url":"https://api.github.com/users/taylorotwell/repos","events_url":"https://api.github.com/users/taylorotwell/events{/privacy}","received_events_url":"https://api.github.com/users/taylorotwell/received_events","type":"User","site_admin":false},"comments":0,"review_comments":0,"maintainer_can_modify":false,"commits":1,"additions":107,"deletions":11,"changed_files":2}}
{"actor":{"display_login":"taylorotwell"}}