This project is archived and is in readonly mode.
Sort the find methods search result if possible
Reported by Johannes Thönes | August 21st, 2008 @ 01:41 PM | in 2.x
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
Comments and changes to this ticket
-
Pratik August 21st, 2008 @ 03:38 PM
- 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.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>