Hi all,

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

  def some_virtual_attribute
    #returns something sortable
  end
end

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

I want to be able to do:
  some_herd.sheep.some_method

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 <=>
b.some_virtual_attribute}
    end
  end

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

With kind regards,
Harm

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to