{"action":"closed","number":22421,"pull_request":{"url":"https://api.github.com/repos/rails/rails/pulls/22421","id":51940632,"html_url":"https://github.com/rails/rails/pull/22421","diff_url":"https://github.com/rails/rails/pull/22421.diff","patch_url":"https://github.com/rails/rails/pull/22421.patch","issue_url":"https://api.github.com/repos/rails/rails/issues/22421","number":22421,"state":"closed","locked":false,"title":"Fix inner explicit ID selection (4.1 Backport of #22251)","user":{"login":"timbreitkreutz","id":42360,"avatar_url":"https://avatars.githubusercontent.com/u/42360?v=3","gravatar_id":"","url":"https://api.github.com/users/timbreitkreutz","html_url":"https://github.com/timbreitkreutz","followers_url":"https://api.github.com/users/timbreitkreutz/followers","following_url":"https://api.github.com/users/timbreitkreutz/following{/other_user}","gists_url":"https://api.github.com/users/timbreitkreutz/gists{/gist_id}","starred_url":"https://api.github.com/users/timbreitkreutz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timbreitkreutz/subscriptions","organizations_url":"https://api.github.com/users/timbreitkreutz/orgs","repos_url":"https://api.github.com/users/timbreitkreutz/repos","events_url":"https://api.github.com/users/timbreitkreutz/events{/privacy}","received_events_url":"https://api.github.com/users/timbreitkreutz/received_events","type":"User","site_admin":false},"body":"Back port of https://github.com/rails/rails/pull/22251\r\n\r\nFix a regression bug (appeared since 4.1.8 and 4.2.0) where a belongs_to relationship would result in failing inner (explicit) selection such as:\r\n\r\n```\r\nPlanet(star: Planet.all.select(:star_id))\r\n```\r\n\r\nThis appeared to happen because the inner relation would get duplicate selections resulting in badly formed SQL such as:\r\n\r\n```\r\nSELECT `planets`.* FROM `planets` WHERE `planets`.`star_id` IN (SELECT `planets`.`star_id`, id FROM `planets`)\r\n```\r\n\r\nThis fix makes it so that extra clauses will not be added to the inner SELECT in the SQL. There were different symptoms in the case of no primary key as well (See Issue #20602 description).","created_at":"2015-11-26T19:04:40Z","updated_at":"2015-11-26T19:16:09Z","closed_at":"2015-11-26T19:16:09Z","merged_at":null,"merge_commit_sha":"7259ea7daf673b4c6102b8b2c18d1ea2dfa8c124","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/rails/rails/pulls/22421/commits","review_comments_url":"https://api.github.com/repos/rails/rails/pulls/22421/comments","review_comment_url":"https://api.github.com/repos/rails/rails/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rails/rails/issues/22421/comments","statuses_url":"https://api.github.com/repos/rails/rails/statuses/a2d604b2216aa9bf523c8cab9e89203c447165ee","head":{"label":"timbreitkreutz:twb-20602-fix-where-on-self-4-1","ref":"twb-20602-fix-where-on-self-4-1","sha":"a2d604b2216aa9bf523c8cab9e89203c447165ee","user":{"login":"timbreitkreutz","id":42360,"avatar_url":"https://avatars.githubusercontent.com/u/42360?v=3","gravatar_id":"","url":"https://api.github.com/users/timbreitkreutz","html_url":"https://github.com/timbreitkreutz","followers_url":"https://api.github.com/users/timbreitkreutz/followers","following_url":"https://api.github.com/users/timbreitkreutz/following{/other_user}","gists_url":"https://api.github.com/users/timbreitkreutz/gists{/gist_id}","starred_url":"https://api.github.com/users/timbreitkreutz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timbreitkreutz/subscriptions","organizations_url":"https://api.github.com/users/timbreitkreutz/orgs","repos_url":"https://api.github.com/users/timbreitkreutz/repos","events_url":"https://api.github.com/users/timbreitkreutz/events{/privacy}","received_events_url":"https://api.github.com/users/timbreitkreutz/received_events","type":"User","site_admin":false},"repo":{"id":43217494,"name":"rails","full_name":"timbreitkreutz/rails","owner":{"login":"timbreitkreutz","id":42360,"avatar_url":"https://avatars.githubusercontent.com/u/42360?v=3","gravatar_id":"","url":"https://api.github.com/users/timbreitkreutz","html_url":"https://github.com/timbreitkreutz","followers_url":"https://api.github.com/users/timbreitkreutz/followers","following_url":"https://api.github.com/users/timbreitkreutz/following{/other_user}","gists_url":"https://api.github.com/users/timbreitkreutz/gists{/gist_id}","starred_url":"https://api.github.com/users/timbreitkreutz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timbreitkreutz/subscriptions","organizations_url":"https://api.github.com/users/timbreitkreutz/orgs","repos_url":"https://api.github.com/users/timbreitkreutz/repos","events_url":"https://api.github.com/users/timbreitkreutz/events{/privacy}","received_events_url":"https://api.github.com/users/timbreitkreutz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/timbreitkreutz/rails","description":"Ruby on Rails","fork":true,"url":"https://api.github.com/repos/timbreitkreutz/rails","forks_url":"https://api.github.com/repos/timbreitkreutz/rails/forks","keys_url":"https://api.github.com/repos/timbreitkreutz/rails/keys{/key_id}","collaborators_url":"https://api.github.com/repos/timbreitkreutz/rails/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/timbreitkreutz/rails/teams","hooks_url":"https://api.github.com/repos/timbreitkreutz/rails/hooks","issue_events_url":"https://api.github.com/repos/timbreitkreutz/rails/issues/events{/number}","events_url":"https://api.github.com/repos/timbreitkreutz/rails/events","assignees_url":"https://api.github.com/repos/timbreitkreutz/rails/assignees{/user}","branches_url":"https://api.github.com/repos/timbreitkreutz/rails/branches{/branch}","tags_url":"https://api.github.com/repos/timbreitkreutz/rails/tags","blobs_url":"https://api.github.com/repos/timbreitkreutz/rails/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/timbreitkreutz/rails/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/timbreitkreutz/rails/git/refs{/sha}","trees_url":"https://api.github.com/repos/timbreitkreutz/rails/git/trees{/sha}","statuses_url":"https://api.github.com/repos/timbreitkreutz/rails/statuses/{sha}","languages_url":"https://api.github.com/repos/timbreitkreutz/rails/languages","stargazers_url":"https://api.github.com/repos/timbreitkreutz/rails/stargazers","contributors_url":"https://api.github.com/repos/timbreitkreutz/rails/contributors","subscribers_url":"https://api.github.com/repos/timbreitkreutz/rails/subscribers","subscription_url":"https://api.github.com/repos/timbreitkreutz/rails/subscription","commits_url":"https://api.github.com/repos/timbreitkreutz/rails/commits{/sha}","git_commits_url":"https://api.github.com/repos/timbreitkreutz/rails/git/commits{/sha}","comments_url":"https://api.github.com/repos/timbreitkreutz/rails/comments{/number}","issue_comment_url":"https://api.github.com/repos/timbreitkreutz/rails/issues/comments{/number}","contents_url":"https://api.github.com/repos/timbreitkreutz/rails/contents/{+path}","compare_url":"https://api.github.com/repos/timbreitkreutz/rails/compare/{base}...{head}","merges_url":"https://api.github.com/repos/timbreitkreutz/rails/merges","archive_url":"https://api.github.com/repos/timbreitkreutz/rails/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/timbreitkreutz/rails/downloads","issues_url":"https://api.github.com/repos/timbreitkreutz/rails/issues{/number}","pulls_url":"https://api.github.com/repos/timbreitkreutz/rails/pulls{/number}","milestones_url":"https://api.github.com/repos/timbreitkreutz/rails/milestones{/number}","notifications_url":"https://api.github.com/repos/timbreitkreutz/rails/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/timbreitkreutz/rails/labels{/name}","releases_url":"https://api.github.com/repos/timbreitkreutz/rails/releases{/id}","created_at":"2015-09-26T18:26:12Z","updated_at":"2015-09-26T18:26:50Z","pushed_at":"2015-11-26T19:04:09Z","git_url":"git://github.com/timbreitkreutz/rails.git","ssh_url":"git@github.com:timbreitkreutz/rails.git","clone_url":"https://github.com/timbreitkreutz/rails.git","svn_url":"https://github.com/timbreitkreutz/rails","homepage":"http://rubyonrails.org","size":119968,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rails:4-1-stable","ref":"4-1-stable","sha":"689df94716bd6443301470602e524486fe65adde","user":{"login":"rails","id":4223,"avatar_url":"https://avatars.githubusercontent.com/u/4223?v=3","gravatar_id":"","url":"https://api.github.com/users/rails","html_url":"https://github.com/rails","followers_url":"https://api.github.com/users/rails/followers","following_url":"https://api.github.com/users/rails/following{/other_user}","gists_url":"https://api.github.com/users/rails/gists{/gist_id}","starred_url":"https://api.github.com/users/rails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rails/subscriptions","organizations_url":"https://api.github.com/users/rails/orgs","repos_url":"https://api.github.com/users/rails/repos","events_url":"https://api.github.com/users/rails/events{/privacy}","received_events_url":"https://api.github.com/users/rails/received_events","type":"Organization","site_admin":false},"repo":{"id":8514,"name":"rails","full_name":"rails/rails","owner":{"login":"rails","id":4223,"avatar_url":"https://avatars.githubusercontent.com/u/4223?v=3","gravatar_id":"","url":"https://api.github.com/users/rails","html_url":"https://github.com/rails","followers_url":"https://api.github.com/users/rails/followers","following_url":"https://api.github.com/users/rails/following{/other_user}","gists_url":"https://api.github.com/users/rails/gists{/gist_id}","starred_url":"https://api.github.com/users/rails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rails/subscriptions","organizations_url":"https://api.github.com/users/rails/orgs","repos_url":"https://api.github.com/users/rails/repos","events_url":"https://api.github.com/users/rails/events{/privacy}","received_events_url":"https://api.github.com/users/rails/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rails/rails","description":"Ruby on Rails","fork":false,"url":"https://api.github.com/repos/rails/rails","forks_url":"https://api.github.com/repos/rails/rails/forks","keys_url":"https://api.github.com/repos/rails/rails/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rails/rails/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rails/rails/teams","hooks_url":"https://api.github.com/repos/rails/rails/hooks","issue_events_url":"https://api.github.com/repos/rails/rails/issues/events{/number}","events_url":"https://api.github.com/repos/rails/rails/events","assignees_url":"https://api.github.com/repos/rails/rails/assignees{/user}","branches_url":"https://api.github.com/repos/rails/rails/branches{/branch}","tags_url":"https://api.github.com/repos/rails/rails/tags","blobs_url":"https://api.github.com/repos/rails/rails/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rails/rails/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rails/rails/git/refs{/sha}","trees_url":"https://api.github.com/repos/rails/rails/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rails/rails/statuses/{sha}","languages_url":"https://api.github.com/repos/rails/rails/languages","stargazers_url":"https://api.github.com/repos/rails/rails/stargazers","contributors_url":"https://api.github.com/repos/rails/rails/contributors","subscribers_url":"https://api.github.com/repos/rails/rails/subscribers","subscription_url":"https://api.github.com/repos/rails/rails/subscription","commits_url":"https://api.github.com/repos/rails/rails/commits{/sha}","git_commits_url":"https://api.github.com/repos/rails/rails/git/commits{/sha}","comments_url":"https://api.github.com/repos/rails/rails/comments{/number}","issue_comment_url":"https://api.github.com/repos/rails/rails/issues/comments{/number}","contents_url":"https://api.github.com/repos/rails/rails/contents/{+path}","compare_url":"https://api.github.com/repos/rails/rails/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rails/rails/merges","archive_url":"https://api.github.com/repos/rails/rails/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rails/rails/downloads","issues_url":"https://api.github.com/repos/rails/rails/issues{/number}","pulls_url":"https://api.github.com/repos/rails/rails/pulls{/number}","milestones_url":"https://api.github.com/repos/rails/rails/milestones{/number}","notifications_url":"https://api.github.com/repos/rails/rails/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rails/rails/labels{/name}","releases_url":"https://api.github.com/repos/rails/rails/releases{/id}","created_at":"2008-04-11T02:19:47Z","updated_at":"2015-11-26T17:14:03Z","pushed_at":"2015-11-26T19:04:41Z","git_url":"git://github.com/rails/rails.git","ssh_url":"git@github.com:rails/rails.git","clone_url":"https://github.com/rails/rails.git","svn_url":"https://github.com/rails/rails","homepage":"http://rubyonrails.org","size":322387,"stargazers_count":28526,"watchers_count":28526,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":11544,"mirror_url":null,"open_issues_count":864,"forks":11544,"open_issues":864,"watchers":28526,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rails/rails/pulls/22421"},"html":{"href":"https://github.com/rails/rails/pull/22421"},"issue":{"href":"https://api.github.com/repos/rails/rails/issues/22421"},"comments":{"href":"https://api.github.com/repos/rails/rails/issues/22421/comments"},"review_comments":{"href":"https://api.github.com/repos/rails/rails/pulls/22421/comments"},"review_comment":{"href":"https://api.github.com/repos/rails/rails/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rails/rails/pulls/22421/commits"},"statuses":{"href":"https://api.github.com/repos/rails/rails/statuses/a2d604b2216aa9bf523c8cab9e89203c447165ee"}},"merged":false,"mergeable":true,"mergeable_state":"unstable","merged_by":null,"comments":1,"review_comments":0,"commits":1,"additions":42,"deletions":2,"changed_files":6}}