diff --git a/app/models/champ.rb b/app/models/champ.rb index 8b65d6ba4..3fcd43563 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -10,7 +10,7 @@ class Champ < ApplicationRecord # here because otherwise we can't easily use includes in our queries. has_many :geo_areas, -> { order(:created_at) }, dependent: :destroy, inverse_of: :champ belongs_to :etablissement, optional: true, dependent: :destroy - has_many :champs, -> { ordered }, foreign_key: :parent_id, inverse_of: :parent + has_many :champs, foreign_key: :parent_id, inverse_of: :parent delegate :procedure, to: :dossier @@ -70,14 +70,6 @@ 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, -> do - includes(:type_de_champ) - .joins(dossier: { revision: :revision_types_de_champ }) - .where('procedure_revision_types_de_champ.type_de_champ_id = champs.type_de_champ_id') - .order(:row_id, :position) - end - scope :public_ordered, -> { public_only.ordered } - scope :private_ordered, -> { private_only.ordered } scope :root, -> { where(parent_id: nil) } scope :prefilled, -> { where(prefilled: true) } diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 8f345fb4f..936b5e9a9 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -45,8 +45,8 @@ class Dossier < ApplicationRecord # We have to remove champs in a particular order - champs with a reference to a parent have to be # removed first, otherwise we get a foreign key constraint error. has_many :champs_to_destroy, -> { order(:parent_id) }, class_name: 'Champ', inverse_of: false, dependent: :destroy - has_many :champs_public, -> { root.public_ordered }, class_name: 'Champ', inverse_of: false - has_many :champs_private, -> { root.private_ordered }, class_name: 'Champ', inverse_of: false + has_many :champs_public, -> { root.public_only }, class_name: 'Champ', inverse_of: false + has_many :champs_private, -> { root.private_only }, class_name: 'Champ', inverse_of: false has_many :champs_public_all, -> { public_only }, class_name: 'Champ', inverse_of: false has_many :champs_private_all, -> { private_only }, class_name: 'Champ', inverse_of: false has_many :prefilled_champs_public, -> { root.public_only.prefilled }, class_name: 'Champ', inverse_of: false