Created
September 13, 2017 13:38
-
-
Save davidakachaos/b0129b73e4c26ba19e0c816e1d1435f7 to your computer and use it in GitHub Desktop.
Return a random ActiveRecord object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveRecord | |
class Base | |
def self.random(max_records = 10_000) | |
find(limit(max_records).pluck(primary_key).sample) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment