使用条件连接的rails中的活动记录查询

时间:2011-10-07 04:49:00

标签: ruby-on-rails-3 activerecord has-many-through

  • 我有模型CategoryDeal,并通过has_many :through进行categories_deals映射。
  • 我有另一个模型City,其has_many :through与[{1}} cities_dealsdeals映射。

现在我想获取第2类和第3类以及第10城市的交易。

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

就像现在指定城市一样。

1 个答案:

答案 0 :(得分:1)

我找到了解决方案..这是:

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