Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Open
mp-dhorsak opened this Issue · 5 comments

6 participants

@mp-dhorsak

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

Error:

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

@arturmalecki

I have checked this, and I will try to fix it.

@arturmalecki

This is complicated issue, I need more time to provide a fix.

@arturmalecki

I have located line which cause this issue:

https://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations/preloader/association.rb#L116

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
@rails-bot
Collaborator

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.

@jturkel

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.