Forum: Ruby on Rails default model order

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2007-02-12 22:49
(Received via mailing list)

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():

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])

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

Comments suggestions improvements?

  Phlip  <-- NOT a blog!!
This topic is locked and can not be replied to.