# Error when Eager Loading "Not unique table/alias"

**URL:** <https://www.ruby-forum.com/t/error-when-eager-loading-not-unique-table-alias/66235>\
**Category:** Rails\
**Created:** [February 12, 2006, 9:59pm UTC](https://www.ruby-forum.com/t/error-when-eager-loading-not-unique-table-alias/66235 "2006-02-12T21:59:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![edconnell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/5e9695/32.png) [@edconnell](https://www.ruby-forum.com/u/edconnell)\
**Post date:** [February 12, 2006, 9:59pm UTC](https://www.ruby-forum.com/t/error-when-eager-loading-not-unique-table-alias/66235/1 "2006-02-12T21:59:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![edconnell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/5e9695/32.png) [@edconnell](https://www.ruby-forum.com/u/edconnell)\
**Post date:** [February 12, 2006, 11:58pm UTC](https://www.ruby-forum.com/t/error-when-eager-loading-not-unique-table-alias/66235/2 "2006-02-12T23:58:05Z")

</div>

This is a known issue with Rails. Check out:

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

---

<div class="post-metadata">

**Author:** ![edconnell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/5e9695/32.png) [@edconnell](https://www.ruby-forum.com/u/edconnell)\
**Post date:** [February 13, 2006, 2:27am UTC](https://www.ruby-forum.com/t/error-when-eager-loading-not-unique-table-alias/66235/3 "2006-02-13T02:27:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![edconnell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/5e9695/32.png) [@edconnell](https://www.ruby-forum.com/u/edconnell)\
**Post date:** [February 13, 2006, 7:26am UTC](https://www.ruby-forum.com/t/error-when-eager-loading-not-unique-table-alias/66235/4 "2006-02-13T07:26:59Z")

</div>

On 2/12/06, Ed C. [removed\_email\_address@domain.invalid](mailto: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.
