I am working on a Rails 3 app, and I need to return back a list of players where the sum of points_received per player, is greater than a specified amount.
I have tried this:
Answer.sum(:points_received, :group => 'player_id').having("points_received > 5")
but of course this gives me an error: NoMethodError: undefined method `having' for #
Answer model is defined as:
create_table "answers", :force => true do |t|
t.integer "player_id"
t.integer "round_id"
t.string "response"
t.integer "points_received"
end
So I understand that sum is returning back an ordered hash of player_id, sum(points_received), but I only want to see the results where the sum(points_received) is greater than a specified value.
Any suggestions?
Thanks in advance!