views:

9

answers:

0

I have two objects:

class Person < ActiveRecord::Base
   has_many :tests
end

class Test <ActiveRecord::Base
   belongs_to :person
end

I need to sort all my person objects by the sum of scores on the test. One other trick is each person may not have a test.

I've gotten as far as this with my tests but I can't get them to order based on the sum of the scores for that person because I can't figure out how to reference the value being calculated.

Score.sum(:score, :group => :person_id)

Once I have this how do I get this back to a list of players to sort?