# Multiple joins to the same table/association with different conditions

**URL:** <https://www.ruby-forum.com/t/multiple-joins-to-the-same-table-association-with-different-conditions/193879>\
**Category:** Rails\
**Created:** [August 26, 2010, 2:23am UTC](https://www.ruby-forum.com/t/multiple-joins-to-the-same-table-association-with-different-conditions/193879 "2010-08-26T02:23:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [August 26, 2010, 2:23am UTC](https://www.ruby-forum.com/t/multiple-joins-to-the-same-table-association-with-different-conditions/193879/1 "2010-08-26T02:23:49Z")

</div>

I’m looking for a nice(!) way to specify multiple joins to the same  
table where there are different conditions on each one.

I was hoping for something like this

class Model \< ActiveRecord::Base  
has\_many :things

```
scope :some_things,
  joins(:things).where('things.foo' => 'bar').
  joins(:things => :others).where('others.foo' => 'baz')

```

end

Unfortunately, this is wishful thinking. As far as I can tell, I have to  
write the SQL for the second join explicitly like this

```
 joins('JOIN things AS others ON models.id = things.model_id')

```

Did I miss a better way?

Michael

–  
Michael S.  
[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.schuerig.de/michael/](http://www.schuerig.de/michael/)
