2015-05-04 68 views
1

我試圖找到使用條件和包括的值的數組。 但流汗一些錯誤..導軌包含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://stackoverflow.com/questions/5947593/how-to-use-in-1-2- 3與 - 的findall –

回答

0

爲什麼你不用where方法嘗試而不是find_all_by_id

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

請嘗試以下操作。

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

發現我自己

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

感謝答案