Forum: Ruby on Rails Error when Eager Loading "Not unique table/alias"

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ed C. (Guest)
on 2006-02-12 22:59
(Received via mailing list)
Hi list,

I get the error "Not unique table/alias" (myql 4.1) when trying eager
load 2 classes that use the same base class (not STI)

Example:

<code>
  class Wedding < ActiveRecord::Base
    belongs_to :bride, :class_name => 'Person', :foreign_key =>
'bride_id'
    belongs_to :groom, :class_name => 'Person', :foreign_key =>
'groom_id'
  end
</code>

Trying to eager load the bride and groom classes blows up because the
"people" table is left outer joined twice:

<code>
  Wedding.find(:first, :include => [:bride, :groom])
</code>

Is there a way to specify an alias for the table name? (like 'LEFT
OUTER JOIN people AS p1')

Any suggestions?

Thanks,
EJC
Pete Y. (Guest)
on 2006-02-13 00:58
(Received via mailing list)
This is a known issue with Rails. Check out:

http://wiki.rubyonrails.org/rails/pages/Allow+Mult...
+Same+Table+Plugin

That fixes that problem and a couple of others, at the expense of a)
throwing an error in one plugin test and b) not working with edge rails.

Cheers,

Pete Y.
Ed C. (Guest)
on 2006-02-13 03:27
(Received via mailing list)
Is this something that'll be address in later versions of Rails, like
1.1? I couldn't quite tell from the tickets.
Jeremy E. (Guest)
on 2006-02-13 08:26
(Received via mailing list)
On 2/12/06, Ed C. <removed_email_address@domain.invalid> wrote:
> Is this something that'll be address in later versions of Rails, like
> 1.1? I couldn't quite tell from the tickets.

I'll probably update the plugin when Rails 1.1 comes out.  I don't
have time to track Edge Rails and update the plugin every time it
breaks.  I feel that this functionality really should be in core, but
it doesn't seem to be a priority for the core team.  I'd happily make
any changes to the patch/plugin to get it accepted into core, but
nobody from the core team has contacted me about it and I'm not
willing to fight an uphill battle when the plugin/patch method is the
path of least resistance.
This topic is locked and can not be replied to.