[英]Rails query interface where clause issue?
我尝试按如下方式运行 SQK 查询
@applicants = Applicant.where("applicants.first_name LIKE ? AND applicants.status = ?", "%#{people}%", ["new", "in-review"] )
我收到一个 MySQL 错误:
ActionView::Template::Error (Mysql2::Error: Operand should contain 1 column(s): SELECT `applicants`.* FROM `applicants` WHERE (applicants.first_name LIKE '%sh%' AND applicants.status = 'new','in-review')):
如果你想传递一个数组,最好写
@applicants = Applicant
.where("applicants.first_name LIKE ?", "%#{people}%")
.where(status: ["new", "in-review"])
或者使用squeel gem。
@applicants = Applicant.where{ (status.in(["new", "in-review"]) & (first_name =~ "%#{people}%") }
你必须使用 mysql 的IN
子句
@applicants = Applicant.where("applicants.first_name LIKE ? AND
applicants.status in (?)",
"%#{people}%", ["new", "in-review"] )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.