导轨包含ID条件的数组

问题描述:

我试图找到使用条件和包括的值的数组。 但流汗一些错误..导轨包含ID条件的数组

下面运作良好,并与用户返回受益人包括

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

可能有助于http://*.com/questions/5947593/how-to-use-in-1-2- 3与 - 的findall –

为什么你不用where方法尝试而不是find_all_by_id

Beneficiary.includes(:caterer_info).where('beneficiaries.id IN (?)', [304,305]) 

请尝试以下操作。

Beneficiary.includes(:caterer_info).where({beneficiaries: {id: [304,305]}}) 

发现我自己

Beneficiary.includes(:user).where("beneficiaries.id IN (?)",ids) 

感谢答案