Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- named_scope :random, lambda { |*args| { :joins => "JOIN (SELECT id
- FROM #{table_name}
- ORDER BY RAND()
- LIMIT #{(limit = args.first.to_i) > 0 ? limit : 1}
- ) AS random_ids
- ON #{table_name}.id = random_ids.id"}}
Add Comment
Please, Sign In to add comment