default model order

Phlip
Mon, 12 Feb 2007 21:48:07 -0000

Railsters:

Suppose you have a model with no reason to find() in any but one
order. The DRYest way to code that would seem to be overriding find().
ActiveRecord seems to encourage this monkey patching by routing
everything thru find():

http://blog.gwikzone.org/articles/2006/09/05/ruby-on-rails-find-with-default-order

That post leads to this slight improvement:

  def Version.find(*args)
    args[1] = { :order => "created_on desc" }.merge(args[1] || {})
if
[:all, :first].include?(args[0])
    super(*args)
  end

The latest version is always at the top of the list.

Comments suggestions improvements?

--
  Phlip
  http://c2.com/cgi/wiki?ZeekLand  <-- NOT a blog!!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---