feat(champ): has_one_attached => has_many_attached piece_justificative_file
This commit is contained in:
parent
2cdbcbf0b6
commit
91f4971df2
5 changed files with 11 additions and 11 deletions
|
@ -23,7 +23,7 @@ class Champ < ApplicationRecord
|
|||
belongs_to :dossier, inverse_of: false, touch: true, optional: false
|
||||
belongs_to :type_de_champ, inverse_of: :champ, optional: false
|
||||
belongs_to :parent, class_name: 'Champ', optional: true
|
||||
has_one_attached :piece_justificative_file
|
||||
has_many_attached :piece_justificative_file
|
||||
|
||||
# We declare champ specific relationships (Champs::CarteChamp, Champs::SiretChamp and Champs::RepetitionChamp)
|
||||
# here because otherwise we can't easily use includes in our queries.
|
||||
|
|
|
@ -261,16 +261,16 @@ class Dossier < ApplicationRecord
|
|||
includes(champs_public: [
|
||||
:type_de_champ,
|
||||
:geo_areas,
|
||||
piece_justificative_file_attachment: :blob,
|
||||
champs: [:type_de_champ, piece_justificative_file_attachment: :blob]
|
||||
piece_justificative_file_attachments: :blob,
|
||||
champs: [:type_de_champ, piece_justificative_file_attachments: :blob]
|
||||
])
|
||||
}
|
||||
scope :with_annotations, -> {
|
||||
includes(champs_private: [
|
||||
:type_de_champ,
|
||||
:geo_areas,
|
||||
piece_justificative_file_attachment: :blob,
|
||||
champs: [:type_de_champ, piece_justificative_file_attachment: :blob]
|
||||
piece_justificative_file_attachments: :blob,
|
||||
champs: [:type_de_champ, piece_justificative_file_attachments: :blob]
|
||||
])
|
||||
}
|
||||
scope :for_api, -> {
|
||||
|
@ -279,7 +279,7 @@ class Dossier < ApplicationRecord
|
|||
.includes(commentaires: { piece_jointe_attachment: :blob },
|
||||
justificatif_motivation_attachment: :blob,
|
||||
attestation: [],
|
||||
avis: { piece_justificative_file_attachment: :blob },
|
||||
avis: { piece_justificative_file_attachments: :blob },
|
||||
traitement: [],
|
||||
etablissement: [],
|
||||
individual: [],
|
||||
|
|
|
@ -35,7 +35,7 @@ class DossierPreloader
|
|||
end
|
||||
|
||||
def load_dossiers(dossiers, pj_template: false)
|
||||
to_include = [piece_justificative_file_attachment: :blob]
|
||||
to_include = [piece_justificative_file_attachments: :blob]
|
||||
|
||||
if pj_template
|
||||
to_include << { type_de_champ: { piece_justificative_template_attachment: :blob } }
|
||||
|
|
|
@ -248,9 +248,9 @@ class Procedure < ApplicationRecord
|
|||
:groupe_instructeurs,
|
||||
dossiers: {
|
||||
champs_public: [
|
||||
piece_justificative_file_attachment: :blob,
|
||||
piece_justificative_file_attachments: :blob,
|
||||
champs: [
|
||||
piece_justificative_file_attachment: :blob
|
||||
piece_justificative_file_attachments: :blob
|
||||
]
|
||||
]
|
||||
}
|
||||
|
@ -776,7 +776,7 @@ class Procedure < ApplicationRecord
|
|||
if dossiers.termine.any?
|
||||
dossiers_sample = dossiers.termine.limit(100)
|
||||
total_size = Champ
|
||||
.includes(piece_justificative_file_attachment: :blob)
|
||||
.includes(piece_justificative_file_attachments: :blob)
|
||||
.where(type: Champs::PieceJustificativeChamp.to_s, dossier: dossiers_sample)
|
||||
.sum('active_storage_blobs.byte_size')
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ class PiecesJustificativesService
|
|||
|
||||
def self.pjs_for_champs(dossiers, for_expert = false)
|
||||
champs = Champ
|
||||
.joins(:piece_justificative_file_attachment)
|
||||
.joins(:piece_justificative_file_attachments)
|
||||
.where(type: "Champs::PieceJustificativeChamp", dossier: dossiers)
|
||||
|
||||
if for_expert
|
||||
|
|
Loading…
Add table
Reference in a new issue