diff --git a/packages/loot-core/src/server/aql/compiler.test.ts b/packages/loot-core/src/server/aql/compiler.test.ts index 9fb50102c5..9614c8bc76 100644 --- a/packages/loot-core/src/server/aql/compiler.test.ts +++ b/packages/loot-core/src/server/aql/compiler.test.ts @@ -1000,7 +1000,9 @@ describe('Type conversions', () => { ); // The SQL should use cat_group instead of "group" in the join condition - expect(result.sql).toMatch(/category_groups\d+\.id = categories\d+\.cat_group/); + expect(result.sql).toMatch( + /category_groups\d+\.id = categories\d+\.cat_group/, + ); expect(result.sql).not.toMatch(/categories\d+\."group"/); }); }); diff --git a/packages/loot-core/src/server/aql/compiler.ts b/packages/loot-core/src/server/aql/compiler.ts index cd4389c4e5..942a92b121 100644 --- a/packages/loot-core/src/server/aql/compiler.ts +++ b/packages/loot-core/src/server/aql/compiler.ts @@ -823,11 +823,11 @@ function compileJoins(state, tableRef, internalTableFilters, schemaConfig) { // Apply field mapping for join field (e.g., 'group' -> 'cat_group') const resolvedJoinField = (() => { const views = schemaConfig?.views || {}; - + // We need to find the actual table name that joinTable refers to // joinTable could be either a table name (first level) or a tableId (deeper levels) let actualTableName = joinTable; - + // If joinTable looks like a table ID (contains numbers), find the actual table name if (typeof joinTable === 'string' && joinTable.match(/\d+$/)) { // Find the table name by looking for a path with this tableId @@ -838,7 +838,7 @@ function compileJoins(state, tableRef, internalTableFilters, schemaConfig) { } } } - + // The joinField belongs to actualTableName (the table we're joining FROM) if (views[actualTableName] && views[actualTableName].fields) { return views[actualTableName].fields[joinField] || joinField;