mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 16:09:52 +01:00
16 lines
470 B
Ruby
16 lines
470 B
Ruby
class Report < ApplicationRecord
|
|
belongs_to :user
|
|
has_many :moderation_votes, dependent: :destroy
|
|
has_many :moderation_comments, dependent: :destroy
|
|
validates :type, presence: true
|
|
validates :target_id, presence: true
|
|
validates :user_id, presence: true
|
|
|
|
def target
|
|
type.sub('Reports::', '').constantize.where(id: target_id).first
|
|
end
|
|
|
|
def votes
|
|
moderation_votes.where(upvote: true).count - moderation_votes.where(upvote: false).count
|
|
end
|
|
end
|