Use has_one defaut_procdre to avoid before destroy prepend

This commit is contained in:
simon lehericey 2023-04-19 13:52:01 +02:00
parent aecd7559d2
commit 9c6af921e5
2 changed files with 2 additions and 4 deletions

View file

@ -21,6 +21,8 @@ class GroupeInstructeur < ApplicationRecord
has_and_belongs_to_many :exports, dependent: :destroy
has_and_belongs_to_many :bulk_messages, dependent: :destroy
has_one :defaut_procedure, -> { with_discarded }, class_name: 'Procedure', foreign_key: :defaut_groupe_instructeur_id, dependent: :nullify, inverse_of: :defaut_groupe_instructeur
validates :label, presence: true, allow_nil: false
validates :label, uniqueness: { scope: :procedure }
validates :closed, acceptance: { accept: [false] }, if: -> { closed_changed? && self.procedure.groupe_instructeurs.active.one? }

View file

@ -210,10 +210,6 @@ class Procedure < ApplicationRecord
belongs_to :defaut_groupe_instructeur, class_name: 'GroupeInstructeur', inverse_of: false, optional: true
before_destroy prepend: true do |record|
record.update(defaut_groupe_instructeur_id: nil)
end
has_one_attached :logo
has_one_attached :notice
has_one_attached :deliberation