diff --git a/app/models/champ.rb b/app/models/champ.rb index 45b3ca866..9408d6bb4 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -237,7 +237,7 @@ class Champ < ApplicationRecord private def champs_for_condition - private? ? dossier.champs_private : dossier.champs_public + dossier.champs.filter { _1.row.nil? || _1.row == row } end def html_id diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 53fbb15b3..805326ee9 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -78,6 +78,7 @@ class Dossier < ApplicationRecord has_one_attached :justificatif_motivation + has_many :champs has_many :champs_public, -> { root.public_ordered }, class_name: 'Champ', inverse_of: false, dependent: :destroy has_many :champs_private, -> { root.private_ordered }, class_name: 'Champ', inverse_of: false, dependent: :destroy has_many :commentaires, inverse_of: :dossier, dependent: :destroy diff --git a/app/models/dossier_preloader.rb b/app/models/dossier_preloader.rb index b8c502075..b0c1a8049 100644 --- a/app/models/dossier_preloader.rb +++ b/app/models/dossier_preloader.rb @@ -78,6 +78,7 @@ class DossierPreloader def load_dossier(dossier, champs, children_by_parent = {}) champs_public, champs_private = champs.partition(&:public?) + dossier.association(:champs).target = [] load_champs(dossier, :champs_public, champs_public, dossier, children_by_parent) load_champs(dossier, :champs_private, champs_private, dossier, children_by_parent) @@ -97,6 +98,7 @@ class DossierPreloader champ.association(:parent).target = parent end end + dossier.association(:champs).target += champs parent.association(name).target = champs.sort_by do |champ| [champ.row, positions[dossier.revision_id][champ.type_de_champ_id]]