{"action":"opened","number":21550,"pull_request":{"url":"https://api.github.com/repos/rails/rails/pulls/21550","id":44439548,"html_url":"https://github.com/rails/rails/pull/21550","diff_url":"https://github.com/rails/rails/pull/21550.diff","patch_url":"https://github.com/rails/rails/pull/21550.patch","issue_url":"https://api.github.com/repos/rails/rails/issues/21550","number":21550,"state":"open","locked":false,"title":"Include association's `unscope` when preloading","user":{"login":"jbourassa","id":224311,"avatar_url":"https://avatars.githubusercontent.com/u/224311?v=3","gravatar_id":"","url":"https://api.github.com/users/jbourassa","html_url":"https://github.com/jbourassa","followers_url":"https://api.github.com/users/jbourassa/followers","following_url":"https://api.github.com/users/jbourassa/following{/other_user}","gists_url":"https://api.github.com/users/jbourassa/gists{/gist_id}","starred_url":"https://api.github.com/users/jbourassa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbourassa/subscriptions","organizations_url":"https://api.github.com/users/jbourassa/orgs","repos_url":"https://api.github.com/users/jbourassa/repos","events_url":"https://api.github.com/users/jbourassa/events{/privacy}","received_events_url":"https://api.github.com/users/jbourassa/received_events","type":"User","site_admin":false},"body":"Preloading an association that is using `unscope` is dropping the `unscope` part.\r\n\r\nAs they say, 20 LoC is worth a thousand words:\r\n```ruby\r\nclass Developer < ActiveRecord::Base\r\n  default_scope -> { where(awesome: true) }\r\nend\r\n\r\nclass Project < ActiveRecord::Base\r\n  has_and_belongs_to_many :developers, -> { unscope(where: :awesome) },\r\nend\r\n\r\nmediocre_dev = Developer.create(awesome: false)\r\nproject = Project.create\r\nproject.developers << mediocre_dev\r\n\r\nproject.developers.reload.size\r\n# => 1\r\nProject.where(id: project.id).includes(:developers).developers.size\r\n# => 0 — but should be 1\r\n```\r\n\r\nThis PR fixes that behaviour. This is my first PR on AR (:tada:) so I'm not all that familiar with the internals, let me know if anything seems wrong.","created_at":"2015-09-08T14:35:21Z","updated_at":"2015-09-08T14:35:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/rails/rails/pulls/21550/commits","review_comments_url":"https://api.github.com/repos/rails/rails/pulls/21550/comments","review_comment_url":"https://api.github.com/repos/rails/rails/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rails/rails/issues/21550/comments","statuses_url":"https://api.github.com/repos/rails/rails/statuses/1d99b1478ffd692a4985548630fc8d2802c54547","head":{"label":"didacte:unscope-associations","ref":"unscope-associations","sha":"1d99b1478ffd692a4985548630fc8d2802c54547","user":{"login":"didacte","id":11947400,"avatar_url":"https://avatars.githubusercontent.com/u/11947400?v=3","gravatar_id":"","url":"https://api.github.com/users/didacte","html_url":"https://github.com/didacte","followers_url":"https://api.github.com/users/didacte/followers","following_url":"https://api.github.com/users/didacte/following{/other_user}","gists_url":"https://api.github.com/users/didacte/gists{/gist_id}","starred_url":"https://api.github.com/users/didacte/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/didacte/subscriptions","organizations_url":"https://api.github.com/users/didacte/orgs","repos_url":"https://api.github.com/users/didacte/repos","events_url":"https://api.github.com/users/didacte/events{/privacy}","received_events_url":"https://api.github.com/users/didacte/received_events","type":"Organization","site_admin":false},"repo":{"id":42116598,"name":"rails","full_name":"didacte/rails","owner":{"login":"didacte","id":11947400,"avatar_url":"https://avatars.githubusercontent.com/u/11947400?v=3","gravatar_id":"","url":"https://api.github.com/users/didacte","html_url":"https://github.com/didacte","followers_url":"https://api.github.com/users/didacte/followers","following_url":"https://api.github.com/users/didacte/following{/other_user}","gists_url":"https://api.github.com/users/didacte/gists{/gist_id}","starred_url":"https://api.github.com/users/didacte/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/didacte/subscriptions","organizations_url":"https://api.github.com/users/didacte/orgs","repos_url":"https://api.github.com/users/didacte/repos","events_url":"https://api.github.com/users/didacte/events{/privacy}","received_events_url":"https://api.github.com/users/didacte/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/didacte/rails","description":"Ruby on Rails","fork":true,"url":"https://api.github.com/repos/didacte/rails","forks_url":"https://api.github.com/repos/didacte/rails/forks","keys_url":"https://api.github.com/repos/didacte/rails/keys{/key_id}","collaborators_url":"https://api.github.com/repos/didacte/rails/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/didacte/rails/teams","hooks_url":"https://api.github.com/repos/didacte/rails/hooks","issue_events_url":"https://api.github.com/repos/didacte/rails/issues/events{/number}","events_url":"https://api.github.com/repos/didacte/rails/events","assignees_url":"https://api.github.com/repos/didacte/rails/assignees{/user}","branches_url":"https://api.github.com/repos/didacte/rails/branches{/branch}","tags_url":"https://api.github.com/repos/didacte/rails/tags","blobs_url":"https://api.github.com/repos/didacte/rails/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/didacte/rails/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/didacte/rails/git/refs{/sha}","trees_url":"https://api.github.com/repos/didacte/rails/git/trees{/sha}","statuses_url":"https://api.github.com/repos/didacte/rails/statuses/{sha}","languages_url":"https://api.github.com/repos/didacte/rails/languages","stargazers_url":"https://api.github.com/repos/didacte/rails/stargazers","contributors_url":"https://api.github.com/repos/didacte/rails/contributors","subscribers_url":"https://api.github.com/repos/didacte/rails/subscribers","subscription_url":"https://api.github.com/repos/didacte/rails/subscription","commits_url":"https://api.github.com/repos/didacte/rails/commits{/sha}","git_commits_url":"https://api.github.com/repos/didacte/rails/git/commits{/sha}","comments_url":"https://api.github.com/repos/didacte/rails/comments{/number}","issue_comment_url":"https://api.github.com/repos/didacte/rails/issues/comments{/number}","contents_url":"https://api.github.com/repos/didacte/rails/contents/{+path}","compare_url":"https://api.github.com/repos/didacte/rails/compare/{base}...{head}","merges_url":"https://api.github.com/repos/didacte/rails/merges","archive_url":"https://api.github.com/repos/didacte/rails/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/didacte/rails/downloads","issues_url":"https://api.github.com/repos/didacte/rails/issues{/number}","pulls_url":"https://api.github.com/repos/didacte/rails/pulls{/number}","milestones_url":"https://api.github.com/repos/didacte/rails/milestones{/number}","notifications_url":"https://api.github.com/repos/didacte/rails/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/didacte/rails/labels{/name}","releases_url":"https://api.github.com/repos/didacte/rails/releases{/id}","created_at":"2015-09-08T14:15:04Z","updated_at":"2015-09-08T14:15:34Z","pushed_at":"2015-09-08T14:18:55Z","git_url":"git://github.com/didacte/rails.git","ssh_url":"git@github.com:didacte/rails.git","clone_url":"https://github.com/didacte/rails.git","svn_url":"https://github.com/didacte/rails","homepage":"http://rubyonrails.org","size":451554,"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:master","ref":"master","sha":"269050072d53bc34d779c4f807c444aacb08a61a","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-09-08T12:54:03Z","pushed_at":"2015-09-08T12:13:57Z","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":451554,"stargazers_count":27610,"watchers_count":27610,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":11089,"mirror_url":null,"open_issues_count":903,"forks":11089,"open_issues":903,"watchers":27610,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rails/rails/pulls/21550"},"html":{"href":"https://github.com/rails/rails/pull/21550"},"issue":{"href":"https://api.github.com/repos/rails/rails/issues/21550"},"comments":{"href":"https://api.github.com/repos/rails/rails/issues/21550/comments"},"review_comments":{"href":"https://api.github.com/repos/rails/rails/pulls/21550/comments"},"review_comment":{"href":"https://api.github.com/repos/rails/rails/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rails/rails/pulls/21550/commits"},"statuses":{"href":"https://api.github.com/repos/rails/rails/statuses/1d99b1478ffd692a4985548630fc8d2802c54547"}},"merged":false,"mergeable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"commits":1,"additions":22,"deletions":1,"changed_files":2}}