models: fix ProcedurePresentation#sorted_ids

The `Dossier#with_notifications` scope needs to be composed with an
`instructeurs` scope. But it seems Rails 6 will only generate proper
SQL if the `instructeurs` scope is merged before filtering on
`with_notifications`.
This commit is contained in:
Pierre de La Morinerie 2020-07-01 11:35:00 +02:00
parent 2f7fbc8474
commit cd65dc14dd

View file

@ -79,7 +79,7 @@ class ProcedurePresentation < ApplicationRecord
case table
when 'notifications'
dossiers_id_with_notification = dossiers.with_notifications.merge(instructeur.followed_dossiers).ids
dossiers_id_with_notification = dossiers.merge(instructeur.followed_dossiers).with_notifications.ids
if order == 'desc'
return dossiers_id_with_notification +
(dossiers.order('dossiers.updated_at desc').ids - dossiers_id_with_notification)