From 0790ffc7033311940833f3d4f33bc332cdffd13a Mon Sep 17 00:00:00 2001 From: Anuj-Gupta4 Date: Mon, 16 Dec 2024 17:38:16 +0545 Subject: [PATCH] fix(mapper-project): include organisation name in project query results --- src/backend/app/db/models.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/backend/app/db/models.py b/src/backend/app/db/models.py index 043a9757b..212d475ee 100644 --- a/src/backend/app/db/models.py +++ b/src/backend/app/db/models.py @@ -1015,6 +1015,7 @@ async def one(cls, db: Connection, project_id: int, minimal: bool = False) -> Se sql = """ SELECT p.*, + project_org.name AS organisation_name, ST_AsGeoJSON(p.outline)::jsonb AS outline, ST_AsGeoJSON(ST_Centroid(p.outline))::jsonb AS centroid, COALESCE( @@ -1032,13 +1033,15 @@ async def one(cls, db: Connection, project_id: int, minimal: bool = False) -> Se projects p LEFT JOIN tasks t ON t.project_id = %(project_id)s + LEFT JOIN + organisations project_org ON p.organisation_id = project_org.id WHERE p.id = %(project_id)s AND ( t.project_id = %(project_id)s -- Also required to return a project with if tasks OR t.project_id IS NULL ) - GROUP BY p.id; + GROUP BY p.id, project_org.name; """ # Full query with all additional calculated fields