Getting access to models collection in Mongoid instead of Criteria object
Whenever I do:
Person.where(...)
I get a Criteria
object. That's understandable. But开发者_JS百科 I couldn't find how do I get access to actual models collection? For now, I have to do this workaround:
Person.where(...).map { |person| person }
And then query gets executed and I have an array of Person
objects. Is there an easier method? #all doesn't seem to work, it returns the same Criteria
object.
Just convert the Criteria object to an array:
Person.all.to_a
精彩评论