具有 table 和指定字段的 AR 友好 where 子句

AR friendly where clause with table and field specified

我如何将其转换为对 AR 更友好的 where 子句?

  relation.where("users.id = (?)", user_id)
end

我试过了

 relation.where(id: ?, user_id)

但我需要指定 table,因为 AR 有多个连接。

因为我希望能够提供单个 user_id 或 user_id 数组。

信息这么少,好像有点不好说。但是,你试过了吗:

relation.where(users: {id: user_id})

user_id可以是一个整数、一个id数组、一个可枚举的用户等