Class: Vote

Inherits:
ApplicationRecord show all
Includes:
PostRelated
Defined in:
app/models/vote.rb

Overview

Represents a vote. A vote is attached to both a ‘post’ (i.e. a question or an answer - this is a polymorphic association), and to a user.

Class Method Summary collapse

Methods inherited from ApplicationRecord

#attributes_print, fuzzy_search, match_search, #match_search, sanitize_for_search, sanitize_name, sanitize_sql_in, useful_err_msg, with_lax_group_rules

Class Method Details

.total_rep_change(col) ⇒ Object



18
19
20
21
22
23
24
# File 'app/models/vote.rb', line 18

def self.total_rep_change(col)
  col = col.includes(:post, post: [:category, :post_type])

  col.reduce(0) do |sum, vote|
    sum + (CategoryPostType.rep_changes[[vote.post.category_id, vote.post.post_type_id]][vote.vote_type] || 0)
  end
end