Error when Eager Loading "Not unique table/alias"


#1

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:

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

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

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

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

Any suggestions?

Thanks,
EJC


#2

This is a known issue with Rails. Check out:

http://wiki.rubyonrails.org/rails/pages/Allow+Multiple+Associations
+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.


#3

Is this something that’ll be address in later versions of Rails, like
1.1? I couldn’t quite tell from the tickets.


#4

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.