From 2bc076e1fb3b28c405fb6ddec27014d83675f5f9 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 23 Apr 2024 11:32:25 +0200 Subject: [PATCH] fix(dossier): fix and optimize dossier projection service --- app/services/dossier_projection_service.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/services/dossier_projection_service.rb b/app/services/dossier_projection_service.rb index 8727f07a5..6a87f0515 100644 --- a/app/services/dossier_projection_service.rb +++ b/app/services/dossier_projection_service.rb @@ -56,12 +56,11 @@ class DossierProjectionService case table when 'type_de_champ', 'type_de_champ_private' Champ - .includes(:type_de_champ) .where( - types_de_champ: { stable_id: fields.map { |f| f[COLUMN] } }, + stable_id: fields.map { |f| f[COLUMN] }, dossier_id: dossiers_ids ) - .select(:dossier_id, :value, :type_de_champ_id, 'types_de_champ.stable_id', :type, :external_id, :data, :value_json) # we cannot pluck :value, as we need the champ.to_s method + .select(:dossier_id, :value, :stable_id, :type, :external_id, :data, :value_json) # we cannot pluck :value, as we need the champ.to_s method .group_by(&:stable_id) # the champs are redispatched to their respective fields .map do |stable_id, champs| field = fields.find { |f| f[COLUMN] == stable_id.to_s }