On 7/14/05, Dane Jensen
<jensen-hTe+RANN9c/LSiWjCY9aRNBPR1lH4CV8@public.gmane.org>
wrote:> I have a people table with four types of people: clients, spouses,
> children, and others all setup using single-table inheritance with a
> foreign key back to a household record.
>
> A Household has_one client and spouse, and has_many children and
> others. I want to use a single "Household.find(@session
> [:household_id], :include => [:client, :spouse, :children,
:others])"
>
> Unfortunately this generates the following error: "Not unique table/
> alias: ''people''" with a mammoth query afterwards
bulling in the same
> columns from people four times.
>
> Does ActiveRecord simply not let single-table inheritance and eager
> loading play nicely together, or am I doing something very wrong?
>
> I''ve worked out an ugly hack if I do a find(... :include =>
:people)
> and then slice up the household.people array into four arrays from
> there, but that doesn''t seem very elegant.
It doesn''t assign aliases to the tables. So, when you include
[:client, :spouse], you''re including two instances of the same table.
--
rick
http://techno-weenie.net