Skip to content

Commit

Permalink
Merge pull request #10372 from tchak/fix-dossier-projection-service
Browse files Browse the repository at this point in the history
fix(dossier): fix and optimize dossier projection service
  • Loading branch information
tchak authored Apr 23, 2024
2 parents 5d61444 + 2bc076e commit 9d5a4a7
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions app/services/dossier_projection_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,11 @@ def self.project(dossiers_ids, fields)
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 }
Expand Down

0 comments on commit 9d5a4a7

Please sign in to comment.