Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Methods to provide random and weighted random ActiveRecord::Relation scopes #25

Merged
merged 1 commit into from
Feb 25, 2014
Merged

Methods to provide random and weighted random ActiveRecord::Relation scopes #25

merged 1 commit into from
Feb 25, 2014

Conversation

paulspringett
Copy link
Contributor

Add order_by_rand and order_by_rand_weighted methods that just append an order clause without applying limits or converting to an Array or single object.

Supersedes #24 and fixes #23

@paulspringett
Copy link
Contributor Author

Provides methods as suggested by @spilliton in #24

Artist.order_by_rand.first 
Artist.order_by_rand.limit(50).to_a
Artist.order_by_rand_weighted(:score).first
Artist.limit(5).order_by_rand_weighted(:score).to_a

@paulspringett
Copy link
Contributor Author

@spilliton I've added the methods as you suggested and updated the existing random and random_weighted methods to make use of them (they still have the same inputs and outputs though).

@spilliton
Copy link
Owner

Looks pretty good to me, nice work! I'll fix the build, looks like it's the pesky posgres specific issue

spilliton added a commit that referenced this pull request Feb 25, 2014
Methods to provide random and weighted random ActiveRecord::Relation scopes
@spilliton spilliton merged commit 028097d into spilliton:master Feb 25, 2014
@paulspringett
Copy link
Contributor Author

@spilliton nice one, thanks for the merge

@spilliton
Copy link
Owner

No problem, I can hopefully get around to a release in the next couple days. I likely won't go 1.0 yet but maybe 0.5.0 or something

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

It is possible that this returns an activerecord_relation instead of a an array?
2 participants