2

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.

Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367
randombits
  • 47,058
  • 76
  • 251
  • 433

2 Answers2

3

You can pass find an array or list of IDs:

Foo.find(1,2,3) or Foo.find([1,2,3])
Peter Brown
  • 50,956
  • 18
  • 113
  • 146
2

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!

Ramon Tayag
  • 15,224
  • 9
  • 43
  • 69