# Dynamically constructing conditions in multiple self join

**URL:** <https://www.ruby-forum.com/t/dynamically-constructing-conditions-in-multiple-self-join/188491>\
**Category:** Rails\
**Created:** [May 12, 2010, 9:46pm UTC](https://www.ruby-forum.com/t/dynamically-constructing-conditions-in-multiple-self-join/188491 "2010-05-12T21:46:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nibble70](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/74df32/32.png) [@nibble70](https://www.ruby-forum.com/u/nibble70)\
**Post date:** [May 12, 2010, 9:46pm UTC](https://www.ruby-forum.com/t/dynamically-constructing-conditions-in-multiple-self-join/188491/1 "2010-05-12T21:46:17Z")

</div>

Hi,

I am using a join that looks like this:

Person.find :all,  
:select =\> ‘children\_people\_3.\*’,  
:joins =\> { :children =\> { :children =\> :children } },  
:conditions =\> {  
:people =\> { :name =\> ‘tom’ },  
:children\_people =\> { :name =\> ‘dick’ },  
:children\_people\_2 =\> { :name =\> ‘harry’ },  
:children\_people\_3 =\> { :name =\> ‘charles’ }  
}

which I don not like because I am hard-coding assumptions about the  
table aliases used for the joins into the conditions.

Can someone tell me how to write the conditions in a more flexible way  
(can they be specified using the hash syntax?), or possibly tell me how  
I could try use the Arel being used to construct the query by the Rails  
core to construct the table aliases that I am hard-coding above.

Rails 3.0.0.beta.

Thanks.
