Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Sort the find methods search result if possible

#878

Hi,

I think it would be useful, if the find methods sorts the search result, if the model searched for responds to the <=> method and no :order option has been passed.

So if I i.e. had:


class Item < ActiveRecordBase
  def <=>(other)
    value <=> other.value
  end
end

Then


Item.find(:all)

would be sorted the way specified. If the <=> is not specfied, sorting should not take place. If the :order option is specified, it should not take place as well.

This is usefull, because sometimes there are no means on specifying the order by sql. I.e. in cardiology you have the following coronar segments: rca1, rca2, rca3, rca4, lca5, lad6, lad7, lad8, lad9, lad10, circ11, circ12, circ13, circ14, circ15. This order is not a lexical order but one given by blood flow. With the <=> method you could handle this i.e. by using the indexes of a constant array.

Johannes

Reported by Johannes Thönes · August 21st, 2008 @ 01:41 PM

State: wontfix
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Pratik
    Pratik
    • State changed from new to wontfix
    • Tag changed from activerecord, patch to activerecord, enhancement, patch

    I don't think this is a common requirement and you should just pluginize this, or simply define a custom finder in the specific application.

    Thanks.

    August 21st, 2008 @ 03:38 PM