From d5f620a1639e3f776dbd6b840271a72b9ba94db5 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 7 Mar 2018 17:42:02 +0100 Subject: [PATCH] Mark 1to1 nested relationships as `update_only` to avoid creating multiple associations This fixes the invalid entreprises without etablissements --- app/models/entreprise.rb | 2 +- app/models/etablissement.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/entreprise.rb b/app/models/entreprise.rb index db62b88ec..57057b52d 100644 --- a/app/models/entreprise.rb +++ b/app/models/entreprise.rb @@ -6,7 +6,7 @@ class Entreprise < ApplicationRecord validates :siren, presence: true validates :dossier_id, uniqueness: true - accepts_nested_attributes_for :rna_information + accepts_nested_attributes_for :rna_information, update_only: true before_save :default_values diff --git a/app/models/etablissement.rb b/app/models/etablissement.rb index ff2885c46..2b718f035 100644 --- a/app/models/etablissement.rb +++ b/app/models/etablissement.rb @@ -5,7 +5,7 @@ class Etablissement < ApplicationRecord has_many :exercices, dependent: :destroy accepts_nested_attributes_for :exercices - accepts_nested_attributes_for :entreprise + accepts_nested_attributes_for :entreprise, update_only: true validates :dossier_id, uniqueness: true