[英]Ohm, find all records from array of ids
I am looking for a way to find all Ohm affiliated objects with one query, by feeding it an array of attributes that are indexed. 我正在寻找一种方法,通过向其提供索引的属性数组来查找一个查询的所有欧姆关联对象。 In Mongoid, this is done with something like:
在Mongoid中,这可以通过以下方式完成:
Foo.any_in(:some_id => [list_of_ids])
ActiveRecord has the find_all
family of methods. ActiveRecord具有
find_all
方法系列。
I essentially want to be able to pull N records from the data store without calling find() 30 times individually. 我本质上希望能够从数据存储中提取N条记录,而无需分别调用30次find()。
您可以传递查找ID的数组或列表:
Foo.find(1,2,3) or Foo.find([1,2,3])
This does not seem to work with the latest Ohm (1.1.1). 这似乎不适用于最新的Ohm(1.1.1)。 I looked through the source and it seems you need to do something like
Model.all.send(:fetch, [1,2,3])
. 我查看了源代码,看来您需要执行类似
Model.all.send(:fetch, [1,2,3])
。 Problem is... you have to call a private method. 问题是...您必须调用私有方法。
I created an issue to see if this is the right approach. 我创建了一个问题 ,看这是否是正确的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.