Skip to content

Commit

Permalink
Fix #4 by calculating points in a single query
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Dayan committed Mar 29, 2017
1 parent dc87027 commit 21c0e52
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/merit/models/active_record/merit/score.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class Score < ActiveRecord::Base
class_name: 'Merit::Score::Point'

def points
score_points.group(:score_id).sum(:num_points).values.first || 0
score_points.select('COALESCE(SUM(num_points), 0) AS num_points')
.first
.num_points
end

class Point < ActiveRecord::Base
Expand Down

0 comments on commit 21c0e52

Please sign in to comment.