Re: has_one :through eager-loading problem

Frederick Cheung
Tue, 16 Sep 2008 16:45:55 -0000

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
> 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..
>
> >