demarches-normaliennes/app/models/follow.rb
Nicolas Bouilleaud 6b90bc1ea1 Add “previously followed” dossiers and gestionnaires
Using an “inactive” Follow scope, similar to the “active” scope.

(I was tempted to use a default_scope, but this breaks when trying to `unscope` it in associations.)
2019-06-12 17:33:53 +02:00

20 lines
537 B
Ruby

class Follow < ApplicationRecord
belongs_to :gestionnaire
belongs_to :dossier
validates :gestionnaire_id, uniqueness: { scope: [:dossier_id, :unfollowed_at] }
before_create :set_default_date
scope :active, -> { where(unfollowed_at: nil) }
scope :inactive, -> { where.not(unfollowed_at: nil) }
private
def set_default_date
self.demande_seen_at ||= Time.zone.now
self.annotations_privees_seen_at ||= Time.zone.now
self.avis_seen_at ||= Time.zone.now
self.messagerie_seen_at ||= Time.zone.now
end
end