Fix champ order joins sql error

This commit is contained in:
Paul Chavard 2020-09-03 18:28:49 +02:00
parent 72afb01cbd
commit 6d4425885d

View file

@ -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) }