# Has\_one :through eager-loading problem

**URL:** <https://www.ruby-forum.com/t/has-one-through-eager-loading-problem/196809>\
**Category:** Rails\
**Created:** [September 16, 2008, 6:43pm UTC](https://www.ruby-forum.com/t/has-one-through-eager-loading-problem/196809 "2008-09-16T18:43:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wurdalag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/6f9a4e/32.png) [@wurdalag](https://www.ruby-forum.com/u/wurdalag)\
**Post date:** [September 16, 2008, 6:43pm UTC](https://www.ruby-forum.com/t/has-one-through-eager-loading-problem/196809/1 "2008-09-16T18:43:46Z")

</div>

I have a problem with the :include option in find for my  
has\_one :through association.

I have Users, Profiles and Customers, all connected to each other with  
a has\_one :through =\> :membership association like this:

class Profile \< ActiveRecord::Base #could also be user or customer

has\_one :membership # i saw an acrticle of Ryan about  
has\_one :through, there this would be has\_many, is this wrong?  
has\_one :user, :through =\> :membership  
has\_one :customer, :through =\> :membership

end

now if I search for profiles with the :include option:

def index  
@profiles = User.find(:all, :include =\> [:user, :customer])  
end

i get an error:

Mysql::Error: #42S22Unknown column ‘users.profile\_id’ in ‘on clause’

obviously, it searches for the profile\_id on the wrong place, it  
should search it in memberships

anyone has an idea? Thanks…

---

<div class="post-metadata">

**Author:** ![wurdalag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/6f9a4e/32.png) [@wurdalag](https://www.ruby-forum.com/u/wurdalag)\
**Post date:** [September 16, 2008, 6:59pm UTC](https://www.ruby-forum.com/t/has-one-through-eager-loading-problem/196809/2 "2008-09-16T18:59:40Z")

</div>

On 16 Sep 2008, at 17:35, eleasar wrote:

> I have a problem with the :include option in find for my  
> has\_one :through association.
> 
> I have Users, Profiles and Customers, all connected to each other with  
> a has\_one :through =\> :membership association like this:

:including of has\_one :through is basically just broken on rails 2.1.  
It’s fixed on edge.

Fred

---

<div class="post-metadata">

**Author:** ![wurdalag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/6f9a4e/32.png) [@wurdalag](https://www.ruby-forum.com/u/wurdalag)\
**Post date:** [September 16, 2008, 7:06pm UTC](https://www.ruby-forum.com/t/has-one-through-eager-loading-problem/196809/3 "2008-09-16T19:06:07Z")

</div>

Thank you!

On 16 Sep., 18:45, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
