From 1f95f68fcc960f9b38527cd403b2e72bdbe24aab Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 4 Oct 2022 17:32:45 +0200 Subject: [PATCH] refactor(dossier_preloader): assign champ.parent --- app/models/dossier_preloader.rb | 4 ++++ spec/models/dossier_preloader_spec.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/dossier_preloader.rb b/app/models/dossier_preloader.rb index 4cf0767e5..1f416da9b 100644 --- a/app/models/dossier_preloader.rb +++ b/app/models/dossier_preloader.rb @@ -80,6 +80,10 @@ class DossierPreloader def load_champs(parent, name, champs, dossier, children_by_parent) champs.each do |champ| champ.association(:dossier).target = dossier + + if parent.is_a?(Champ) + champ.association(:parent).target = parent + end end parent.association(name).target = champs.sort_by do |champ| diff --git a/spec/models/dossier_preloader_spec.rb b/spec/models/dossier_preloader_spec.rb index 610a932bd..c25a58fb2 100644 --- a/spec/models/dossier_preloader_spec.rb +++ b/spec/models/dossier_preloader_spec.rb @@ -30,7 +30,7 @@ describe DossierPreloader do expect(first_child.parent).to eq(repetition) end - expect(count).to eq(1) + expect(count).to eq(0) end end end