procedure.dossiers through revisions
This commit is contained in:
parent
f30a8b154e
commit
a3f3b8a8e0
4 changed files with 10 additions and 5 deletions
|
@ -56,7 +56,7 @@ class Procedure < ApplicationRecord
|
|||
MAX_DUREE_CONSERVATION = 36
|
||||
MAX_DUREE_CONSERVATION_EXPORT = 3.hours
|
||||
|
||||
has_many :revisions, -> { order(:id) }, class_name: 'ProcedureRevision', inverse_of: :procedure, dependent: :destroy
|
||||
has_many :revisions, -> { order(:id) }, class_name: 'ProcedureRevision', inverse_of: :procedure
|
||||
belongs_to :draft_revision, class_name: 'ProcedureRevision', optional: false
|
||||
belongs_to :published_revision, class_name: 'ProcedureRevision', optional: true
|
||||
has_many :deleted_dossiers, dependent: :destroy
|
||||
|
@ -90,7 +90,10 @@ class Procedure < ApplicationRecord
|
|||
has_many :groupe_instructeurs, dependent: :destroy
|
||||
has_many :instructeurs, through: :groupe_instructeurs
|
||||
|
||||
has_many :dossiers, through: :groupe_instructeurs, dependent: :restrict_with_exception
|
||||
# This relationship is used in following dossiers through. We can not use revisions relationship
|
||||
# as order scope introduces invalid sql in some combinations.
|
||||
has_many :unordered_revisions, class_name: 'ProcedureRevision', inverse_of: :procedure, dependent: :destroy
|
||||
has_many :dossiers, through: :unordered_revisions, dependent: :restrict_with_exception
|
||||
|
||||
has_one :initiated_mail, class_name: "Mails::InitiatedMail", dependent: :destroy
|
||||
has_one :received_mail, class_name: "Mails::ReceivedMail", dependent: :destroy
|
||||
|
|
|
@ -160,7 +160,7 @@ class ProcedurePresentation < ApplicationRecord
|
|||
.filter_ilike(table, column, values)
|
||||
when 'groupe_instructeur'
|
||||
dossiers
|
||||
.includes(table)
|
||||
.joins(:groupe_instructeur)
|
||||
.filter_ilike(table, column, values)
|
||||
end.pluck(:id)
|
||||
end.reduce(:&)
|
||||
|
|
|
@ -11,6 +11,8 @@ class ProcedureRevision < ApplicationRecord
|
|||
self.implicit_order_column = :created_at
|
||||
belongs_to :procedure, -> { with_discarded }, inverse_of: :revisions, optional: false
|
||||
|
||||
has_many :dossiers, inverse_of: :revision, foreign_key: :revision_id
|
||||
|
||||
has_many :revision_types_de_champ, -> { public_only.ordered }, class_name: 'ProcedureRevisionTypeDeChamp', foreign_key: :revision_id, dependent: :destroy, inverse_of: :revision
|
||||
has_many :revision_types_de_champ_private, -> { private_only.ordered }, class_name: 'ProcedureRevisionTypeDeChamp', foreign_key: :revision_id, dependent: :destroy, inverse_of: :revision
|
||||
has_many :types_de_champ, through: :revision_types_de_champ, source: :type_de_champ
|
||||
|
|
|
@ -734,7 +734,7 @@ describe ProcedurePresentation do
|
|||
let!(:gi_3) { procedure.groupe_instructeurs.create(label: '3') }
|
||||
|
||||
let!(:kept_dossier) { create(:dossier, procedure: procedure) }
|
||||
let!(:discarded_dossier) { create(:dossier, groupe_instructeur: gi_2) }
|
||||
let!(:discarded_dossier) { create(:dossier, procedure: procedure, groupe_instructeur: gi_2) }
|
||||
|
||||
it { is_expected.to contain_exactly(kept_dossier.id) }
|
||||
|
||||
|
@ -746,7 +746,7 @@ describe ProcedurePresentation do
|
|||
]
|
||||
end
|
||||
|
||||
let!(:other_kept_dossier) { create(:dossier, groupe_instructeur: gi_3) }
|
||||
let!(:other_kept_dossier) { create(:dossier, procedure: procedure, groupe_instructeur: gi_3) }
|
||||
|
||||
it 'returns every dossier that matches any of the search criteria for a given column' do
|
||||
is_expected.to contain_exactly(kept_dossier.id, other_kept_dossier.id)
|
||||
|
|
Loading…
Reference in a new issue