Order by dynamic field

To accomplish that you need to fetch all the involved rows, and order the objects in Ruby land:

   @models = MyModel.find_all_by_foo(foo).sort {|a, b| ... }

Of course that may be too expensive, depending on the amount of data. If that was the case, you could consider maintaining those calculations via AR callbacks and cache them in some column. That way, you'd delegate ordering to the database.

-- fxn