Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以将 OR 语句添加到 rails 模型中的范围参数,例如
scope :west_coast, where(:st => "CA" || "WA" || "OR")
问题实际上是如何WHERE ... IN使用 activerecord 进行 sql 语句:
WHERE ... IN
scope :west_coast, where(st: %w(CA WA OR))
试试这个:
scope :west_coast, where(['st = ? or st = ? or st = ?'], "CA", "WA", "OR")