From 0d4d0ec801a41e7547316325afb6f32523c75be2 Mon Sep 17 00:00:00 2001 From: Du Peng Date: Mon, 11 Sep 2023 18:04:02 +0200 Subject: [PATCH] (bug) Polymorphic joins for table supporting_document_files supportable --- app/workers/supporting_documents_reminder_worker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/workers/supporting_documents_reminder_worker.rb b/app/workers/supporting_documents_reminder_worker.rb index dfe9ca42c..6aa1a2910 100644 --- a/app/workers/supporting_documents_reminder_worker.rb +++ b/app/workers/supporting_documents_reminder_worker.rb @@ -8,7 +8,7 @@ class SupportingDocumentsReminderWorker users_to_notify = User.members .supporting_documents_reminder_not_sent .where("users.created_at < ?", 2.days.ago) - .left_outer_joins(supporting_document_files: { supporting_document_type: :groups }) + .joins("LEFT OUTER JOIN supporting_document_files ON supporting_document_files.supportable_id = users.id AND supporting_document_files.supportable_type = 'User' LEFT OUTER JOIN supporting_document_types ON supporting_document_types.id = supporting_document_files.supporting_document_type_id LEFT OUTER JOIN supporting_document_types_groups ON supporting_document_types_groups.supporting_document_type_id = supporting_document_types.id LEFT OUTER JOIN groups ON groups.id = supporting_document_types_groups.group_id") .where("groups.id = users.group_id OR groups.id IS NULL") .select("users.*, count(supporting_document_files.id)") .group("users.id")