https://github.com/norman/active_record_random
Monkey patch to ActiveRecord to allow :order => :random that works the same for MySQL, SQLite and Postgres.
https://github.com/norman/active_record_random
Last synced: 6 months ago
JSON representation
Monkey patch to ActiveRecord to allow :order => :random that works the same for MySQL, SQLite and Postgres.
- Host: GitHub
- URL: https://github.com/norman/active_record_random
- Owner: norman
- License: mit
- Created: 2009-01-12T19:25:34.000Z (almost 17 years ago)
- Default Branch: master
- Last Pushed: 2010-07-10T22:20:36.000Z (over 15 years ago)
- Last Synced: 2025-04-28T16:55:28.377Z (9 months ago)
- Homepage:
- Size: 88.9 KB
- Stars: 9
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.rdoc
- License: MIT-LICENSE
Awesome Lists containing this project
README
= ActiveRecordRandom
This plugin adds
:order => :random
to all the default ActiveRecord adapters. This means you can do this:
Post.find(:all, :order => :random, :limit => 10)
and it will work for MySQL, SQLite or Postgres without having to change the
query. It also works for named scopes:
named_scope :randomized, :order => :random
== Why?
Because MySQL has a different syntax than Postgres and SQLite for ordering by
random. If you develop or test on SQLite and then deploy on MySQL, this is
annoying. This plugin solves the problem.
== Shouldn't this be a patch to Rails?
I {submitted it as a
patch}[http://rails.lighthouseapp.com/projects/8994/tickets/1274-patch-add-support-for-order-random-in-queries],
but I'm such a loser that nobody gave me a +1. So for now it's just a lowly
plugin.
Copyright (c) 2009 {Norman Clarke}[mailto:norman@randomba.org], released under the MIT license