Add act as paranoid to related content, with not_hidden scope using hidden_at

This commit is contained in:
Bertocq
2017-12-20 01:55:32 +01:00
parent eac810cc6d
commit 4d2d7c1a0a

View File

@@ -2,6 +2,9 @@ class RelatedContent < ActiveRecord::Base
RELATED_CONTENT_SCORE_THRESHOLD = Setting['related_content_score_threshold'].to_f
RELATIONABLE_MODELS = %w{proposals debates}.freeze
acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases
belongs_to :parent_relationable, polymorphic: true, touch: true
belongs_to :child_relationable, polymorphic: true, touch: true
has_one :opposite_related_content, class_name: 'RelatedContent', foreign_key: :related_content_id
@@ -16,6 +19,7 @@ class RelatedContent < ActiveRecord::Base
after_create :create_opposite_related_content, unless: proc { opposite_related_content.present? }
scope :not_hidden, -> { where('positive_score - negative_score / LEAST(nullif(positive_score + negative_score, 0), 1) >= ?', RELATED_CONTENT_SCORE_THRESHOLD) }
scope :not_hidden, -> { where(hidden_at: nil) }
def score(value)
RelatedContentsScore.create(user_id: current_user, related_content_id: self, score: value)