From 4d2d7c1a0aa0c45f44efee600ccc54aaf7c48328 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 20 Dec 2017 01:55:32 +0100 Subject: [PATCH] Add act as paranoid to related content, with not_hidden scope using hidden_at --- app/models/related_content.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/related_content.rb b/app/models/related_content.rb index dec8b4360..a170c7dca 100644 --- a/app/models/related_content.rb +++ b/app/models/related_content.rb @@ -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)