Merge pull request #5538 from tchak/fix-champ-order-joins

Fix champ order joins sql error
This commit is contained in:
Keirua 2020-09-04 11:27:43 +02:00 committed by GitHub
commit 0ec63672a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -48,7 +48,13 @@ class Champ < ApplicationRecord
scope :private_only, -> { where(private: true) } scope :private_only, -> { where(private: true) }
scope :ordered, -> { includes(:type_de_champ).order(:row, 'types_de_champ.order_place') } 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 :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) } scope :root, -> { where(parent_id: nil) }