我知道有3種主要符號為whereActiveRecord方法提供參數:純弦數組雜湊指定and的where方法是直截了當:# Pure String notationPerson.where("name = 'Neil' AND age = 27")# Array notationPerson.where(["name = ? AND age = ?", 'Neil', 27])# Hash notationPerson.where({name: "Neil", age: 27})指定or相同的where方法讓我很困惑哈希語法??赡軉??# Pure String notationPerson.where("name = 'Neil' OR age = 27")# Array notationPerson.where(["name = ? OR age = ?", 'Neil', 27])# Hash notation DOESN'T WORKPerson.where({name: "Neil" OR age: 27})
2 回答

FFIVE
TA貢獻1797條經驗 獲得超6個贊
正如potashin所說,您可以使用另一個實現此功能的第三方插件。我使用Squeel的時間很長,為此和其他功能(例如復雜的子查詢或聯接)工作得很好。
該查詢使用squeel:
@people= Person.where{(name == 'Neil') | (age = 27)}
- 2 回答
- 0 關注
- 630 瀏覽
添加回答
舉報
0/150
提交
取消