Reputation: 21877
Say I have 100,000 Tweets. How can I use active record to very efficiently select just one Tweet?
Tweet.all => [100K Records]
I want => Tweet.find_by_id[random] (something like this)
Upvotes: 2
Views: 136
Reputation: 13198
I would avoid selecting all and just build random into your query, something like this:
Tweet.find(:first, :order => "RAND()")
Upvotes: 2