Order on virtual attribute in has_many

Hi all,

Consider the following models:
class Sheep < AR::B
  belongs_to :herd

  def some_virtual_attribute
    #returns something sortable

class Herd < AR::B
  has_many :sheep do
    def some_method
      #do something useful

I want to be able to do:

But the collection sheep should be sorted on the
some_virtual_attribute of Sheep.

I tried something along the line of:
  has_many :sheep do
    def ordered
       sort {|a,b| a.some_virtual_attribute <=>

This however returns an instance of Array on which the 'some_method'
is not defined. How can I solve this?

With kind regards,

To get this to work, you'd need to return an AssociationCollection,
which is going to be tricky. Association extensions aren't *generally*
combinable like this; I think you may be thinking about named scopes.

--Matt Jones