fix(dossier): fix preloader with champs outside of revision

This commit is contained in:
Paul Chavard 2024-10-18 18:17:17 +02:00
parent fcb868c6a8
commit fb07bdb8aa
No known key found for this signature in database

View file

@ -63,7 +63,8 @@ class DossierPreloader
def load_etablissements(champs) def load_etablissements(champs)
to_include = @includes_for_etablissement.dup to_include = @includes_for_etablissement.dup
champs_siret = champs.filter(&:siret?) # `champs.siret?` will delegate to type_de_champ; this is not what we want here
champs_siret = champs.filter { _1.type == 'Champs::SiretChamp' }
etablissements_by_id = Etablissement.includes(to_include).where(id: champs_siret.map(&:etablissement_id).compact).index_by(&:id) etablissements_by_id = Etablissement.includes(to_include).where(id: champs_siret.map(&:etablissement_id).compact).index_by(&:id)
champs_siret.each do |champ| champs_siret.each do |champ|
etablissement = etablissements_by_id[champ.etablissement_id] etablissement = etablissements_by_id[champ.etablissement_id]