0

我尝试按如下方式运行 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')):
4

2 回答 2

3

如果你想传递一个数组,最好写

@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}%") }
于 2013-05-16T04:56:10.177 回答
1

你必须使用INmysql的子句

@applicants = Applicant.where("applicants.first_name LIKE ? AND 
                               applicants.status in (?)", 
                               "%#{people}%", ["new", "in-review"] )
于 2013-05-16T04:55:08.703 回答