Reputation: 1776
I perform a query like, for example:
CarrotTopProps.where(funny: false)
which returns an ActiveRecord_Relation object.
Now, I need the first, say, 10 results of that query, I can write:
CarrotTopProps.where(funny: false).first(10)
but that will give me an Array object. Crazy as it might sound, I need the resulting object to maintain the ActiveRecord_Relation class.
Is there a way to do that?
Upvotes: 1
Views: 467
Reputation: 3268
Use limit
and - if you want the "first" objects, combine it with order
.
CarrotTopProps.where(funny: false).limit(10)
yields an ActiveRecord::Relation
http://api.rubyonrails.org/classes/ActiveRecord/QueryMethods.html#method-i-limit
Upvotes: 4