我尝试使用where where和includes来查找值数组。 但是得到了一些错误..
以下效果很好并且包含用户的受益人
Beneficiary.includes(:user).where("beneficiaries.id = ?",304)
但是当我尝试使用ID数组时,我会收到一些错误
Beneficiary.includes(:caterer_info).where("beneficiaries.id = ?",[304,305])
ActiveRecord::StatementInvalid: Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '304,305)'
答案 0 :(得分:1)
请尝试以下操作。
Beneficiary.includes(:caterer_info).where({beneficiaries: {id: [304,305]}})
答案 1 :(得分:0)
为什么不尝试使用where
方法而不是find_all_by_id
Beneficiary.includes(:caterer_info).where('beneficiaries.id IN (?)', [304,305])
答案 2 :(得分:0)
自己找到了答案
Beneficiary.includes(:user).where("beneficiaries.id IN (?)",ids)
由于