Load Fix
This commit is contained in:
@@ -357,7 +357,18 @@ export default async function resourceRoutes(server: FastifyInstance) {
|
|||||||
for (const colName of distinctColumns.split(",").map(c => c.trim())) {
|
for (const colName of distinctColumns.split(",").map(c => c.trim())) {
|
||||||
const col = (table as any)[colName];
|
const col = (table as any)[colName];
|
||||||
if (!col) continue;
|
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();
|
distinctValues[colName] = [...new Set(dRows.map(r => r.v).filter(v => v != null && v !== ""))].sort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user