Add act as paranoid to related content, with not_hidden scope using hidden_at
This commit is contained in:
@@ -2,6 +2,9 @@ class RelatedContent < ActiveRecord::Base
|
|||||||
RELATED_CONTENT_SCORE_THRESHOLD = Setting['related_content_score_threshold'].to_f
|
RELATED_CONTENT_SCORE_THRESHOLD = Setting['related_content_score_threshold'].to_f
|
||||||
RELATIONABLE_MODELS = %w{proposals debates}.freeze
|
RELATIONABLE_MODELS = %w{proposals debates}.freeze
|
||||||
|
|
||||||
|
acts_as_paranoid column: :hidden_at
|
||||||
|
include ActsAsParanoidAliases
|
||||||
|
|
||||||
belongs_to :parent_relationable, polymorphic: true, touch: true
|
belongs_to :parent_relationable, polymorphic: true, touch: true
|
||||||
belongs_to :child_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
|
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? }
|
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('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)
|
def score(value)
|
||||||
RelatedContentsScore.create(user_id: current_user, related_content_id: self, score: value)
|
RelatedContentsScore.create(user_id: current_user, related_content_id: self, score: value)
|
||||||
|
|||||||
Reference in New Issue
Block a user