Mohit Jain
Mohit Jain

Reputation: 43919

Active record query in rails with conditional join

Now I want to fetch deals in category 2 and 3 and city 10.

CategoriesDeal.where(:category_id=>[2,3])

Like how to specify city now.

Upvotes: 1

Views: 1808

Answers (1)

Mohit Jain
Mohit Jain

Reputation: 43919

I figured out the solution.. Here it is:

Deal.all(:joins=>[:cities, :categories], :conditions=>["cities.id= ? and categories.id IN (?)",2, [62,43]]).uniq

Upvotes: 1

Related Questions