我想做这样的事情,但它不起作用:
Something.where(:user => "hello" or :user => "bye")
谢谢
答案 0 :(得分:4)
如果你在同一个字段上进行OR,你应该能够传入一个数组:
Something.where(:user => ["hello", "bye"])
否则,您需要构建OR SQL查询:
Something.where("user = ? or user = ?", "hello", "bye")
答案 1 :(得分:1)
你可以这样做:
Something.where("user = ? OR user = ?", 'hello', 'bye')
甚至是这样:
Something.where("user IN (?)", ['hello', 'bye'] )`
答案 2 :(得分:0)
为了补充现有答案,Arel在工作:
Something.where(Something.arel_table[:attr].in(["val1", "val2"]))
在Arel(https://gist.github.com/1333253)上使用简单的包装器:
Something.where(Something[:attr] >> ["val1", "val2"])