In the case, where has_one :through refers to a model that is a child class, includes causes AR to create invalid SQL.
My gist is an example of this behaviour: https://gist.github.com/mp-dhorsak/8977542
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: geographies.type: SELECT "addresses".* FROM "addresses" WHERE "geographies"."type" IN ('Country') AND "addresses"."user_id" IN (1)
The problem occurs in both Rails 4.0.2 and 4.1.0.beta1
I have checked this, and I will try to fix it.
This is complicated issue, I need more time to provide a fix.
I have located line which cause this issue:
The problem is that AR adds "geographies"."type" IN ('Country') to address query.
"geographies"."type" IN ('Country')
I'm still working on it.
Fixed problem with through association with STI. #14046
This issue has been automatically marked as stale because it has not been commented on for at least
The resources of the Rails team are limited, and so we are asking for your help.
If you can still reproduce this error on the 4-1-stable, 4-0-stable branches or on master,
please reply with all of the information you have about it in order to keep the issue open.
Thank you for all your contributions.
I've verified that this problem still reproduces on master.