Default model order


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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs