我知道有3种主要符号为where
ActiveRecord方法提供参数:
- 纯弦
- 数组
- 杂凑
指定and
的where
方法是直截了当:
# Pure String notation
Person.where("name = 'Neil' AND age = 27")
# Array notation
Person.where(["name = ? AND age = ?", 'Neil', 27])
# Hash notation
Person.where({name: "Neil", age: 27})
指定or
相同的where
方法让我很困惑哈希语法。可能吗?
# Pure String notation
Person.where("name = 'Neil' OR age = 27")
# Array notation
Person.where(["name = ? OR age = ?", 'Neil', 27])
# Hash notation DOESN'T WORK
Person.where({name: "Neil" OR age: 27})
arel
回答是特别好,因为这是何等的被添加到该导轨5,据我所知。