这是我的状态代码数组 = [1,2,3,4,5],在我的 claim 表中有 status_code。我在那里存储状态代码。现在我想找到那些状态代码为 [1,2,4] 的 Claim。那我怎么才能找到。
我写了这个查询:Claim.where("status_code IN (1,2)") 有效但我需要传递数组。那么如何在“In”查询中传递数组。
感谢帮助。
最佳答案
假设status_code 是整型。可以直接在where子句中使用数组。
array = [1,2,3,4,5]
Claim.where(status_code: array)
或
array = [1,2,3,4,5]
Claim.where('claims.status_code IN (?)', array)
关于MySQL 在查询中使用数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22919601/