Default order for models?

Hi Joe --

Is there a way to specify the default order for models?

No, there isn't.

For the sake of consistency, I think there should be -- when you're doing associations you can specify the order there, (as in has_many :foos, :order => 'created_at desc'), so why not a default order for the model?

You could always override the find method in your model class, though. Something like:

   def self.find(*args)
     if args.first.is_a?(Symbol)
       args << {} if args.size < 2
       args.last.reverse_merge! :order => "#{self.table_name}.name"
       super args.first, args.last
     else
       super
     end
   end

That would give you a default order by on 'name', which could be overridden by specifying the :order option explicitly, as per usual.

HTH

/Jeff