diff --git a/app/models/champ.rb b/app/models/champ.rb index 67601b599..dc8007442 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -10,6 +10,7 @@ class Champ < ApplicationRecord scope :updated_since?, -> (date) { where('champs.updated_at > ?', date) } scope :public_only, -> { where(private: false) } scope :private_only, -> { where(private: true) } + scope :ordered, -> { includes(:type_de_champ).order('types_de_champ.order_place') } def public? !private? diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 646aee849..c02facd83 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -104,15 +104,11 @@ class Dossier < ApplicationRecord end def ordered_champs - # TODO: use the line below when the procedure preview does not leak champ with dossier_id == 0 - # champs.joins(:type_de_champ).order('types_de_champ.order_place') - champs.joins(', types_de_champ').where("champs.type_de_champ_id = types_de_champ.id AND types_de_champ.procedure_id = #{procedure.id}").order('order_place') + champs.ordered end def ordered_champs_private - # TODO: use the line below when the procedure preview does not leak champ with dossier_id == 0 - # champs_private.includes(:type_de_champ).order('types_de_champ.order_place') - champs_private.joins(', types_de_champ').where("champs.type_de_champ_id = types_de_champ.id AND types_de_champ.procedure_id = #{procedure.id}").order('order_place') + champs_private.ordered end def ordered_pieces_justificatives