Eager-load the dossier’s procedure when possible

This commit is contained in:
gregoirenovel 2017-04-13 15:42:54 +02:00
parent 6bb67d639c
commit 14b7badfed
3 changed files with 3 additions and 3 deletions

View file

@ -165,7 +165,7 @@ class Users::DossiersController < UsersController
end
def procedure_libelle
dossier = Dossier.find(params[:dossier_id])
dossier = Dossier.includes(:procedure).find(params[:dossier_id])
render json: { procedureLibelle: dossier.procedure.libelle }
rescue ActiveRecord::RecordNotFound
render json: {}, status: 404

View file

@ -39,7 +39,7 @@
.col-xs-5.depositaire-info{ id: "champ-#{champ.id}-value" }
- unless champ.decorate.value.blank?
- if champ.type_champ == 'dossier_link'
- dossier = Dossier.find_by(id: champ.decorate.value)
- dossier = Dossier.includes(:procedure).find_by(id: champ.decorate.value)
- if dossier && gestionnaire_signed_in?
= link_to(dossier.procedure.libelle, backoffice_dossier_path(champ.decorate.value), target: '_blank')
- else

View file

@ -1,4 +1,4 @@
- dossier = Dossier.find_by(id: champ.value)
- dossier = Dossier.includes(:procedure).find_by(id: champ.value)
- show_procedure_libelle = dossier ? true : false
- show_warning = !show_procedure_libelle && champ.value.present?
- procedure_libelle = dossier.nil? ? '' : dossier.procedure.libelle