demarches-normaliennes/app/models/follow.rb

36 lines
1.1 KiB
Ruby
Raw Normal View History

2020-08-06 16:35:45 +02:00
# == Schema Information
#
# Table name: follows
#
# id :integer not null, primary key
# annotations_privees_seen_at :datetime not null
# avis_seen_at :datetime not null
# demande_seen_at :datetime not null
# messagerie_seen_at :datetime not null
# unfollowed_at :datetime
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# instructeur_id :integer not null
#
2018-03-06 13:44:29 +01:00
class Follow < ApplicationRecord
belongs_to :instructeur, optional: false
belongs_to :dossier, optional: false
validates :instructeur_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
2018-10-25 15:07:15 +02:00
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
2017-04-04 15:27:04 +02:00
end