I have Account model,
class Account < ActiveRecord::Base
has_many :account_games
def score
account_games.map(&:score).sum
end
end
And AccountGame :
class AccountGame < ActiveRecord::Base
belongs_to :account
end
What is the best way to get accounts with the highest score? as you can see, score is the summation of related account_games score field.
Thanks