Michael Schuerig
2010-Aug-26 00:22 UTC
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 Schuerig mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org http://www.schuerig.de/michael/ -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.