通过在rails3中使用IN运算符来查找位置。

| 我正在尝试运行如下所示的sql
select name from appointments where location_id in (2,3,4)
以下不起作用。我正在使用
PostgreSQL
a = [2,3,4]
Appointment.select(:name).where(\"location_id IN ?\", a)

ActiveRecord::StatementInvalid: PGError: ERROR:  syntax error at or near \"2\"
LINE 1: ... FROM       \"appointments\"  WHERE     (location_id IN 2,3,4)
                                                                 ^
: SELECT     name FROM       \"appointments\"  WHERE     (location_id IN 2,3,4)
    
已邀请:
您可以使用此:
Appointment.select(:name).where(:location_id => [2,3,4])
希望这可以帮助     
我不知道Rails,但是在我看来您需要这样做:
Appointment.select(:name).where(\"location_id IN (?)\", a)
即在
?
周围放括号。     

要回复问题请先登录注册