- I have models
Category
andDeal
and havinghas_many :through
mapping viacategories_deals
. - I have a another model,
City
, which ha开发者_高级运维s ahas_many :through
mapping viacities_deals
withdeals
.
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.
I figured out the solution.. Here it is:
Deal.all(:joins=>[:cities, :categories], :conditions=>["cities.id= ? and categories.id IN (?)",2, [62,43]]).uniq
精彩评论