Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #3088 (closed enhancement: invalid)

Opened 4 years ago

Last modified 2 years ago

Add option to set default sort order for ActiveRecord objects

Reported by: jason@mugfu.com Assigned to: David
Priority: normal Milestone:
Component: ActiveRecord Version: 0.14.3
Severity: normal Keywords:
Cc:

Description

As far as I can tell, the only possible way to define a sort order to a model's find(:all) call is to supply an :order option. e.g.

MyEntity.find(:all, :order=>"foo")

I think it would be nice to have a setting on the model object to define a default sort column if none is defined., e.g.:

class MyEntity < ActiveRecord::Base
  set_default_order "foo"
end

If the user supplied a sort order to the find method as an option, the sort order would of course then be overriden with the supplied column. If the user wants no sorting applied, they could use: MyEntity.find(:all, :order=>nil). (Or not specify any default ordering to begin with)

Change History

05/25/07 03:26:30 changed by danger

  • status changed from new to closed.
  • resolution set to invalid.

This would be useful as a plugin but is not necessary for the core. For an extremely detailed look at how this plugin could be made please see: http://www.railsforum.com/viewtopic.php?id=682