[英]How can I make an 'OR' statement in ActiveRecord?
I am trying to create an 'OR' sql statement in ActiveRecord 3, I tried all kinds of variations but can't figure it out... 我试图在ActiveRecord 3中创建一个'OR'sql语句,我尝试了各种各样的变化,但无法弄清楚...
For example I want this query to include multiple 'channel_ids' and have it return all posts for any of the channel IDs. 例如,我希望此查询包含多个“channel_ids”,并让它返回任何频道ID的所有帖子。 This works for one: 这适用于一个:
Post.where(:user => 'mike').where(:channel_id => 0).limit(20)
but I cant figure out how to do it with multiples, I've tried for example: 但我无法弄清楚如何用倍数来做,我试过例如:
Post.where(:user => 'mike').where(:channel_id => ?, [0,1,2,3]).limit(20)
but it didn't work. 但它不起作用。 How can I make this work? 我怎样才能做到这一点?
试试这个:
Post.where("posts.user = ? OR posts.channel_id IN (?)", "mike", ids)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.