我知道有3种主要符号为whereActiveRecord方法提供参数:
纯弦
数组
杂凑
指定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})
FFIVE
相关分类