From a126f5efb31aa630875b23b4659c7208d98ad4a5 Mon Sep 17 00:00:00 2001 From: Milos Despotovic Date: Tue, 20 Aug 2024 14:05:13 -0700 Subject: [PATCH] Fix sql query for combining raw and ministry correspondences --- .../models/FOIApplicantCorrespondencesRawRequests.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/request-management-api/request_api/models/FOIApplicantCorrespondencesRawRequests.py b/request-management-api/request_api/models/FOIApplicantCorrespondencesRawRequests.py index 3c587dbe9..3e9f2e805 100644 --- a/request-management-api/request_api/models/FOIApplicantCorrespondencesRawRequests.py +++ b/request-management-api/request_api/models/FOIApplicantCorrespondencesRawRequests.py @@ -49,7 +49,12 @@ def getapplicantcorrespondencesrawrequests(cls, requestid): created_at, createdby, sentcorrespondencemessage, parentapplicantcorrespondenceid, sentby, sent_at, isdraft, isdeleted, isresponse, response_at from "FOIApplicantCorrespondencesRawRequests" rawcorr - where foirawrequest_id = :requestid + where foirawrequest_id = ( + SELECT foirawrequestid FROM public."FOIRequests" + WHERE foirequestid = :requestid + ORDER BY foirequestid ASC, version DESC limit 1) + OR + foirawrequest_id = :requestid order by applicantcorrespondenceid desc, version desc""" rs = db.session.execute(text(sql), {'requestid': requestid}) for row in rs: