私は非常に単純な評判システムを定義しています。
class Post < ActiveRecord::Base
has_reputation :votes, :source => :user, :aggregated_by => :sum
def upvote(user)
self.add_or_update_evaluation(:votes, 1, user)
end
def downvote(user)
self.add_or_update_evaluation(:votes, -1, user)
end
def score
self.reputation_for(:score).to_i
end
end
class User < ActiveRecord::Base
has_reputation :karma,
:source => [:reputation => :votes, :of => :posts, :weight => 10],
:aggregated_by => :sum
def karma
self.reputation_for(:karma).to_i
end
end
ほとんどの場合、それは機能します。ユーザーは自分の投票、賛成票または反対票を変更でき、投稿のスコアが正しく返されます。
ただし、投稿の1つに2つの賛成票がある場合にユーザーのカルマを取得すると、カルマは20であると予想されますが、10が返されます。ここで何が問題なのですか?