diff --git a/app/models/champ.rb b/app/models/champ.rb index b4231596c..a4f5b35ad 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -48,7 +48,13 @@ class Champ < ApplicationRecord scope :private_only, -> { where(private: true) } scope :ordered, -> { includes(:type_de_champ).order(:row, 'types_de_champ.order_place') } scope :public_ordered, -> { public_only.joins(dossier: { revision: :revision_types_de_champ }).where('procedure_revision_types_de_champ.type_de_champ_id = champs.type_de_champ_id').order(:position) } - scope :private_ordered, -> { private_only.joins(dossier: { revision: :revision_types_de_champ_private }).where('procedure_revision_types_de_champ.type_de_champ_id = champs.type_de_champ_id').order(:position) } + # we need to do private champs order as manual join to avoid conflicting join names + scope :private_ordered, -> do + private_only.joins('INNER JOIN types_de_champ types_de_champ_private + ON types_de_champ_private.id = champs.type_de_champ_id AND types_de_champ_private.private = true + INNER JOIN procedure_revision_types_de_champ procedure_revision_types_de_champ_private + ON procedure_revision_types_de_champ_private.type_de_champ_id = types_de_champ_private.id').order(:position) + end scope :root, -> { where(parent_id: nil) }