ordering a collection by an association's property

Posted by neiled on Stack Overflow See other posts from Stack Overflow or by neiled
Published on 2010-03-31T22:23:33Z Indexed on 2010/03/31 22:33 UTC
Read the original article Hit count: 138

Filed under:
|
|
class Person
  belongs_to :team

class Status
  #has last_updated property

class Team
  has_many :members, :class => "Person"

Ok, so I have a Team class which has many People in it and each of those people has a status and each status has a last_updated property.

I'm currently rendering a partial with a collection similar to:

 =render :partial => "user", :collection => current_user.team.members

Now how do I go about sorting the collection by the last_updated property of the Status class?

Thanks in advance!

p.s. I've just written the ruby code from memory, it's just an example, it's not meant to compile but I hope you get the idea!

© Stack Overflow or respective owner

Related posts about ruby

Related posts about ruby-on-rails