From 7326065590f5ba5524c486fc69815f89438fdad6 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Thu, 30 Aug 2018 12:26:09 +0200 Subject: [PATCH] [fix #2486] Include all needed attributes on downloadable_sorted to avoid N+1 select --- app/models/dossier.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 301c11d50..e96aa26a1 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -56,7 +56,7 @@ class Dossier < ApplicationRecord scope :en_construction, -> { not_archived.state_en_construction } scope :en_instruction, -> { not_archived.state_en_instruction } scope :termine, -> { not_archived.state_termine } - scope :downloadable_sorted, -> { state_not_brouillon.includes(:etablissement, :champs, :champs_private).order(en_construction_at: 'asc') } + scope :downloadable_sorted, -> { state_not_brouillon.includes(:etablissement, :champs, :champs_private, :user, :individual, :followers_gestionnaires).order(en_construction_at: 'asc') } scope :en_cours, -> { not_archived.state_en_construction_ou_instruction } scope :without_followers, -> { left_outer_joins(:follows).where(follows: { id: nil }) } scope :followed_by, -> (gestionnaire) { joins(:follows).where(follows: { gestionnaire: gestionnaire }) }