Reputation: 383
I am try to run the SQK query as follows
@applicants = Applicant.where("applicants.first_name LIKE ? AND applicants.status = ?", "%#{people}%", ["new", "in-review"] )
I am getting a MySQL error as :
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')):
Upvotes: 0
Views: 365
Reputation: 1279
If you want pass an array it should be better to write
@applicants = Applicant
.where("applicants.first_name LIKE ?", "%#{people}%")
.where(status: ["new", "in-review"])
Or use squeel gem.
@applicants = Applicant.where{ (status.in(["new", "in-review"]) & (first_name =~ "%#{people}%") }
Upvotes: 4
Reputation: 47472
You have to use IN
clause of mysql
@applicants = Applicant.where("applicants.first_name LIKE ? AND
applicants.status in (?)",
"%#{people}%", ["new", "in-review"] )
Upvotes: 1