fix(geoportal): use subquery instead of JOIN for gis_cladiri_status view

LEFT JOIN caused duplicate rows and column conflicts. Replaced with a
correlated subquery (LIMIT 1) to safely look up BUILD_LEGAL from the
parent parcel's enrichment.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
AI Assistant
2026-03-24 16:16:06 +02:00
parent ba71ca3ef5
commit 0dc5e58b55
@@ -47,14 +47,18 @@ const VIEWS = [
f."cadastralRef" AS cadastral_ref,
f."areaValue" AS area_value,
f."isActive" AS is_active,
COALESCE((p.enrichment->>'BUILD_LEGAL')::int, -1) AS build_legal,
f.geom
FROM "GisFeature" f
LEFT JOIN "GisFeature" p
ON p.siruta = f.siruta
COALESCE(
(SELECT (p.enrichment->>'BUILD_LEGAL')::int
FROM "GisFeature" p
WHERE p.siruta = f.siruta
AND p."cadastralRef" = f."cadastralRef"
AND (p."layerId" LIKE 'TERENURI%' OR p."layerId" LIKE 'CADGEN_LAND%')
AND p.enrichment IS NOT NULL
LIMIT 1),
-1
) AS build_legal,
f.geom
FROM "GisFeature" f
WHERE f.geom IS NOT NULL
AND (f."layerId" LIKE 'CLADIRI%' OR f."layerId" LIKE 'CADGEN_BUILDING%')`,
},