[Feature Request] adding .sample to ActiveRecord

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[Feature Request] adding .sample to ActiveRecord

Regan Ryan
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

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Feature Request] adding .sample to ActiveRecord

Rafael Mendonça França
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.


On Wed, Mar 28, 2018 at 1:21 AM Regan Ryan <[hidden email]> wrote:
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

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.