Multiple joins to the same table/association with different conditions

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:[email protected]
http://www.schuerig.de/michael/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs