{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/14046","repository_url":"https://api.github.com/repos/rails/rails","labels_url":"https://api.github.com/repos/rails/rails/issues/14046/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/14046/comments","events_url":"https://api.github.com/repos/rails/rails/issues/14046/events","html_url":"https://github.com/rails/rails/issues/14046","id":27528610,"number":14046,"title":"has_one :through eager loading using includes creates invalid SQL","user":{"login":"ghost","id":10137,"avatar_url":"https://avatars.githubusercontent.com/u/10137?v=3","gravatar_id":"","url":"https://api.github.com/users/ghost","html_url":"https://github.com/ghost","followers_url":"https://api.github.com/users/ghost/followers","following_url":"https://api.github.com/users/ghost/following{/other_user}","gists_url":"https://api.github.com/users/ghost/gists{/gist_id}","starred_url":"https://api.github.com/users/ghost/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ghost/subscriptions","organizations_url":"https://api.github.com/users/ghost/orgs","repos_url":"https://api.github.com/users/ghost/repos","events_url":"https://api.github.com/users/ghost/events{/privacy}","received_events_url":"https://api.github.com/users/ghost/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rails/rails/labels/activerecord","name":"activerecord","color":"0b02e1"},{"url":"https://api.github.com/repos/rails/rails/labels/attached%20PR","name":"attached PR","color":"006b75"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2014-02-13T15:56:48Z","updated_at":"2016-03-13T17:24:44Z","closed_at":null,"body":"In the case, where `has_one :through` refers to a model that is a child class, `includes` causes AR to create invalid SQL.\r\n\r\nMy gist is an example of this behaviour: https://gist.github.com/mp-dhorsak/8977542\r\n\r\nError: \r\n\r\n```\r\nActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: geographies.type: SELECT \"addresses\".* FROM \"addresses\"  WHERE \"geographies\".\"type\" IN ('Country') AND \"addresses\".\"user_id\" IN (1)\r\n```\r\n\r\nThe problem occurs in both Rails 4.0.2 and 4.1.0.beta1\r\n"},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/196005520","html_url":"https://github.com/rails/rails/issues/14046#issuecomment-196005520","issue_url":"https://api.github.com/repos/rails/rails/issues/14046","id":196005520,"user":{"login":"magikid","id":115515,"avatar_url":"https://avatars.githubusercontent.com/u/115515?v=3","gravatar_id":"","url":"https://api.github.com/users/magikid","html_url":"https://github.com/magikid","followers_url":"https://api.github.com/users/magikid/followers","following_url":"https://api.github.com/users/magikid/following{/other_user}","gists_url":"https://api.github.com/users/magikid/gists{/gist_id}","starred_url":"https://api.github.com/users/magikid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/magikid/subscriptions","organizations_url":"https://api.github.com/users/magikid/orgs","repos_url":"https://api.github.com/users/magikid/repos","events_url":"https://api.github.com/users/magikid/events{/privacy}","received_events_url":"https://api.github.com/users/magikid/received_events","type":"User","site_admin":false},"created_at":"2016-03-13T17:24:44Z","updated_at":"2016-03-13T17:24:44Z","body":"It looks @ghost deleted their account and the associated gist.  Does anyone still have reproduction steps?"}}