Skip to content


Subversion checkout URL

You can clone with
Download ZIP


has_one :through eager loading using includes creates invalid SQL #14046

mp-dhorsak opened this Issue · 5 comments

6 participants


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:


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.

I'm still working on it.

@rails-bot rails-bot added the stale label

This issue has been automatically marked as stale because it has not been commented on for at least
three months.

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.

@rafaelfranca rafaelfranca removed the stale label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.