Rails ActiveRecord where or clause

后端 未结 4 1475
滥情空心
滥情空心 2020-12-20 16:26

I\'m looking to write an ActiveRecord query and this is what I have below. Unfortunately you can\'t use OR like this. What\'s the best way to execute? category_ids<

4条回答
  •  一个人的身影
    2020-12-20 16:59

    One way is to revert to raw sql...

    YourModel.where("categories.id IN ? OR category_relationships.category_id IN ?", category_ids, category_ids)
    

提交回复
热议问题