ActiveRecord where field = ?可能值的数组 [英] ActiveRecord where field = ? array of possible values
本文介绍了ActiveRecord where field = ?可能值的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想做
Model.where('id = ?', [array of values])
如何在不将 OR 语句链接在一起的情况下完成此查找?
How do I accomplish this look up without chaining OR statements together?
推荐答案
来自这里似乎是使用 SQL in
语句完成的:
From here it appears to be done using an SQL in
statement:
Model.where('id IN (?)', [array of values])
或者更简单,正如 kdeisz 指出的(使用 Arel 创建 SQL 查询):
Or more simply, as kdeisz pointed out (Using Arel to create the SQL query):
Model.where(id: [array of values])
这篇关于ActiveRecord where field = ?可能值的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文