[#2179] update champ and individual association with default
That way, they are safe to read in update_search_terms, and no reload is needed later
This commit is contained in:
parent
9e0f812429
commit
333f4e8824
1 changed files with 9 additions and 5 deletions
|
@ -69,10 +69,11 @@ class Dossier < ApplicationRecord
|
|||
delegate :france_connect_information, to: :user
|
||||
|
||||
before_validation :update_state_dates, if: -> { state_changed? }
|
||||
|
||||
before_save :build_default_champs, if: Proc.new { procedure_id_changed? }
|
||||
before_save :build_default_individual, if: Proc.new { procedure.for_individual? }
|
||||
before_save :update_search_terms
|
||||
|
||||
after_save :build_default_champs, if: Proc.new { saved_change_to_procedure_id? }
|
||||
after_save :build_default_individual, if: Proc.new { procedure.for_individual? }
|
||||
after_save :send_dossier_received
|
||||
after_save :send_web_hook
|
||||
after_create :send_draft_notification_email
|
||||
|
@ -105,14 +106,17 @@ class Dossier < ApplicationRecord
|
|||
end
|
||||
|
||||
def build_default_champs
|
||||
procedure.all_types_de_champ.each do |type_de_champ|
|
||||
type_de_champ.champ.create(dossier: self)
|
||||
procedure.types_de_champ.each do |type_de_champ|
|
||||
champs << type_de_champ.champ.build
|
||||
end
|
||||
procedure.types_de_champ_private.each do |type_de_champ|
|
||||
champs_private << type_de_champ.champ.build
|
||||
end
|
||||
end
|
||||
|
||||
def build_default_individual
|
||||
if Individual.where(dossier_id: self.id).count == 0
|
||||
Individual.create(dossier: self)
|
||||
build_individual
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue