从一系列ID中获取所有Rails记录

Don*_*n P 1 postgresql ruby-on-rails rails-activerecord

我有一系列记录ID ["303", "430", "4321", "5102"].我想使用SQL获取与这些ID匹配的所有记录:

acceptable_ids = ["303", "430", "4321", "5102"]
@users = User.where("is_awesome = true AND id IN acceptable_ids)
Run Code Online (Sandbox Code Playgroud)

给出了这个错误:

ActiveRecord::StatementInvalid (PG::SyntaxError: ERROR:  syntax error at or near "["
Run Code Online (Sandbox Code Playgroud)

编写查询以获取所有匹配ID的用户的正确方法是什么acceptable_ids

注意:

我知道User.find(acceptable_ids),但不能使用它,因为我正在使用select,where和join子句构建SQL查询.

Kyl*_*cot 9

User.where(is_awesome: true, id: acceptable_ids)
Run Code Online (Sandbox Code Playgroud)