diff --git a/app/models/prefill_champs.rb b/app/models/prefill_champs.rb index f013c96d4..12d9c8ca0 100644 --- a/app/models/prefill_champs.rb +++ b/app/models/prefill_champs.rb @@ -23,7 +23,7 @@ class PrefillChamps .to_h dossier - .find_champs_by_stable_ids(value_by_stable_id.keys) + .champs_for_prefill(value_by_stable_id.keys) .map { |champ| [champ, value_by_stable_id[champ.stable_id]] } .map { |champ, value| PrefillValue.new(champ:, value:, dossier:) } end diff --git a/app/models/types_de_champ/prefill_repetition_type_de_champ.rb b/app/models/types_de_champ/prefill_repetition_type_de_champ.rb index 7ff8076ed..e90457e4b 100644 --- a/app/models/types_de_champ/prefill_repetition_type_de_champ.rb +++ b/app/models/types_de_champ/prefill_repetition_type_de_champ.rb @@ -54,14 +54,17 @@ class TypesDeChamp::PrefillRepetitionTypeDeChamp < TypesDeChamp::PrefillTypeDeCh def to_assignable_attributes return unless repetition.is_a?(Hash) - row = champ.rows[index] || champ.add_row(champ.dossier_revision) + row = champ.rows[index] || champ.add_row(revision) + row_id = row.first.row_id repetition.map do |key, value| next unless key.is_a?(String) && key.starts_with?("champ_") - subchamp = row.find { |champ| champ.stable_id == Champ.stable_id_from_typed_id(key) } - next unless subchamp + stable_id = Champ.stable_id_from_typed_id(key) + type_de_champ = revision.types_de_champ.find { _1.stable_id == stable_id } + next unless type_de_champ + subchamp = champ.dossier.champ_for_update(type_de_champ, row_id) TypesDeChamp::PrefillTypeDeChamp.build(subchamp.type_de_champ, revision).to_assignable_attributes(subchamp, value) end.compact end