From f26d6bd4f38c6e840e69f4b470a5a3db622ab2b9 Mon Sep 17 00:00:00 2001 From: florianfederspiel Date: Mon, 16 Feb 2026 13:56:45 +0100 Subject: [PATCH] Load Fix --- backend/src/routes/resources/main.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/backend/src/routes/resources/main.ts b/backend/src/routes/resources/main.ts index c05d514..4eb81dc 100644 --- a/backend/src/routes/resources/main.ts +++ b/backend/src/routes/resources/main.ts @@ -357,7 +357,18 @@ export default async function resourceRoutes(server: FastifyInstance) { for (const colName of distinctColumns.split(",").map(c => c.trim())) { const col = (table as any)[colName]; if (!col) continue; - const dRows = await server.db.select({ v: col }).from(table).where(whereCond); + let distinctQuery = server.db.select({ v: col }).from(table).$dynamic(); + if (config.mtoLoad) { + config.mtoLoad.forEach(rel => { + const relConfig = resourceConfig[rel + "s"] || resourceConfig[rel]; + if (!relConfig) return; + const relTable = relConfig.table; + if (relTable !== table) { + distinctQuery = distinctQuery.leftJoin(relTable, eq(table[rel], relTable.id)); + } + }); + } + const dRows = await distinctQuery.where(whereCond); distinctValues[colName] = [...new Set(dRows.map(r => r.v).filter(v => v != null && v !== ""))].sort(); } }