开发者

Active record query in rails with conditional join

  • I have models Category and Deal and having has_many :through mapping via categories_deals.
  • I have a another model, City, which ha开发者_高级运维s a has_many :through mapping via cities_deals with deals.

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜