From 91f4971df20b9b8bbcba34ff643c753d26888918 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Thu, 20 Oct 2022 10:14:47 +0200 Subject: [PATCH] feat(champ): has_one_attached => has_many_attached piece_justificative_file --- app/models/champ.rb | 2 +- app/models/dossier.rb | 10 +++++----- app/models/dossier_preloader.rb | 2 +- app/models/procedure.rb | 6 +++--- app/services/pieces_justificatives_service.rb | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/models/champ.rb b/app/models/champ.rb index 8852b85c5..45b3ca866 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -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. diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 16ebe8a2d..bb2690aa5 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -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: [], diff --git a/app/models/dossier_preloader.rb b/app/models/dossier_preloader.rb index 017b6cb8a..b8c502075 100644 --- a/app/models/dossier_preloader.rb +++ b/app/models/dossier_preloader.rb @@ -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 } } diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 1d001c70b..55fda2185 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -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') diff --git a/app/services/pieces_justificatives_service.rb b/app/services/pieces_justificatives_service.rb index 03f981598..d3fa8990b 100644 --- a/app/services/pieces_justificatives_service.rb +++ b/app/services/pieces_justificatives_service.rb @@ -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