# ARel table aliases

**URL:** <https://www.ruby-forum.com/t/arel-table-aliases/190207>\
**Category:** Rails\
**Created:** [June 17, 2010, 4:22pm UTC](https://www.ruby-forum.com/t/arel-table-aliases/190207 "2010-06-17T16:22:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pat\_Allan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/5f8ce5/32.png) [@Pat\_Allan](https://www.ruby-forum.com/u/Pat_Allan)\
**Post date:** [June 17, 2010, 4:22pm UTC](https://www.ruby-forum.com/t/arel-table-aliases/190207/1 "2010-06-17T16:22:20Z")

</div>

Hi all

I’m battling a little with Rails 3 - trying to get Thinking Sphinx  
working with it. What I need is some way to interrogate ARel joins to  
find out table aliases, given a certain association hierarchy.

For example - a forum has a creator (User model), and many topics. Each  
topic has a creator as well. So, this is a valid query:

Forum.joins(:creator).joins(:topics =\> :creator)

The resulting SQL has two references to the users table - how can I  
interrogate the relation object to find out the users table alias for  
the :topics =\> :creator association path?

A far more detailed analysis of what I want can be found as a gist:

> <https://gist.github.com/pat/441625>

Any suggestions very much welcome.

Cheers

–  
Pat  
e: removed\_email\_address@domain.invalid || m: +614 1327 3337  
w: [http://freelancing-gods.com](http://freelancing-gods.com) || t: [twitter.com/pat](http://twitter.com/pat)  
bounce: [http://trampolineday.com](http://trampolineday.com) || skype: patallan
