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})