Fix update external id after validation

This commit is contained in:
Damien Le Thiec 2022-10-04 17:19:16 +02:00
parent 4ce6cd0072
commit e694ff1f60

View file

@ -23,7 +23,7 @@ class Champs::RNAChamp < Champ
validates :value, allow_blank: true, format: { validates :value, allow_blank: true, format: {
with: /\AW[0-9]{9}\z/, message: I18n.t(:not_a_rna, scope: 'activerecord.errors.messages') with: /\AW[0-9]{9}\z/, message: I18n.t(:not_a_rna, scope: 'activerecord.errors.messages')
} }
after_validation :update_external_id, if: -> { value.present? && external_id.blank? } after_validation :update_external_id, if: -> { value_changed? }
delegate :id, to: :procedure, prefix: true delegate :id, to: :procedure, prefix: true
@ -44,6 +44,6 @@ class Champs::RNAChamp < Champ
end end
def update_external_id def update_external_id
update(external_id: value) self.external_id = self.value
end end
end end