Frage

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:

Foo.any_in(:some_id => [list_of_ids])

ActiveRecord has the find_all family of methods.

I essentially want to be able to pull N records from the data store without calling find() 30 times individually.

War es hilfreich?

Lösung

You can pass find an array or list of IDs:

Foo.find(1,2,3) or Foo.find([1,2,3])

Andere Tipps

This does not seem to work with the latest 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]). Problem is... you have to call a private method.

I created an issue to see if this is the right approach.

UPDATE: It was just made public!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top