2019-08-19 16:12:30 +02:00
|
|
|
class GroupeInstructeur < ApplicationRecord
|
2019-08-27 15:28:02 +02:00
|
|
|
DEFAULT_LABEL = 'défaut'
|
2020-03-31 14:51:07 +02:00
|
|
|
belongs_to :procedure, -> { with_discarded }, inverse_of: :groupe_instructeurs
|
2020-06-11 10:08:04 +02:00
|
|
|
has_many :assign_tos, dependent: :destroy
|
|
|
|
has_many :instructeurs, through: :assign_tos
|
2019-08-22 17:58:31 +02:00
|
|
|
has_many :dossiers
|
2020-06-11 12:33:29 +02:00
|
|
|
has_and_belongs_to_many :exports, dependent: :destroy
|
2019-10-09 18:05:43 +02:00
|
|
|
|
|
|
|
validates :label, presence: { message: 'doit être renseigné' }, allow_nil: false
|
|
|
|
validates :label, uniqueness: { scope: :procedure, message: 'existe déjà' }
|
|
|
|
|
|
|
|
before_validation -> { label&.strip! }
|
2020-01-07 17:39:50 +01:00
|
|
|
|
|
|
|
scope :without_group, -> (group) { where.not(id: group) }
|
2020-04-08 19:30:16 +02:00
|
|
|
scope :for_api_v2, -> { includes(procedure: [:administrateurs]) }
|
2019-08-19 16:12:30 +02:00
|
|
|
end
|