[Feature Request] adding .sample to ActiveRecord

22 views
Skip to first unread message

Regan Ryan

unread,
Mar 28, 2018, 1:21:16 AM3/28/18
to Ruby on Rails: Core
Hi there,

I've never contributed to Rails before, so if I'm doing something wrong, please point me in the right direction.

I often do something like `User.all.sample` in Rails console to get a random record. This is ok, but it loads every record from the db before calling `sample` to get a single record. Some projects have 100k+ users, so that takes some time.

I would like to contribute to Rails by adding a `ActiveRecord::Scoping::Named::ClassMethods#sample` method to retrieve a single (or more if an argument is specified) random record from the db.

I've been reading a couple of "how to contribute to rails" guides, one of them led me to this group. Is anyone able to guide me from here? How do I get approval for this feature?

Cheers,
Regan

Rafael Mendonça França

unread,
Mar 28, 2018, 1:33:33 AM3/28/18
to rubyonra...@googlegroups.com
One of the first things to do is check if this feature would not proposed before. I think you will see that it was already proposed and rejected.


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages