where
我知道为ActiveRecord 方法提供参数有 3 个主要符号:
- 纯字符串
- 大批
- 哈希
指定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})