【发布时间】:2013-02-21 08:04:30
【问题描述】:
我有帐户模型,
class Account < ActiveRecord::Base
has_many :account_games
def score
account_games.map(&:score).sum
end
end
还有 AccountGame:
class AccountGame < ActiveRecord::Base
belongs_to :account
end
获得最高分帐户的最佳方法是什么?如您所见, score 是相关 account_games score 字段的总和。
谢谢
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 rails-activerecord