refactor(dossier): remove champ ordered scope

This commit is contained in:
Paul Chavard 2024-02-12 17:05:25 +01:00
parent 1193c866bf
commit 662917799b
2 changed files with 3 additions and 11 deletions

View file

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

View file

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