Not doing so has a few gotchas when working with relations, particularly with records which are not stored in the database. I'm excluding the related content file because it's got a very peculiar relationship with itself: the `has_one :opposite_related_content` has no inverse; the relation itself is its inverse. It's a false positive since the inverse condition is true: ``` content.opposite_related_content.opposite_related_content.object_id == content.object_id ```
19 lines
499 B
Ruby
19 lines
499 B
Ruby
module Flaggable
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
has_many :flags, as: :flaggable, inverse_of: :flaggable
|
|
scope :flagged, -> { where("flags_count > 0") }
|
|
scope :pending_flag_review, -> { flagged.where(ignored_flag_at: nil, hidden_at: nil) }
|
|
scope :with_ignored_flag, -> { flagged.where.not(ignored_flag_at: nil).where(hidden_at: nil) }
|
|
end
|
|
|
|
def ignored_flag?
|
|
ignored_flag_at.present?
|
|
end
|
|
|
|
def ignore_flag
|
|
update(ignored_flag_at: Time.current)
|
|
end
|
|
end
|