From 48498f61dd05bcd3449d2da573076a0a1afb3810 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Thu, 4 Jan 2024 13:19:22 +0000 Subject: [PATCH] fix: usage in formula --- .../src/db/formulav2/formulaQueryBuilderv2.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts b/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts index fe055a5a5d..745e6633c3 100644 --- a/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts +++ b/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts @@ -644,8 +644,12 @@ async function _formulaQueryBuilder( { const refCol = await getRefColumnIfAlias(col); + if (refCol.id in aliasToColumn) { + aliasToColumn[col.id] = aliasToColumn[refCol.id]; + break; + } if (knex.clientType().startsWith('mysql')) { - aliasToColumn[refCol.id] = async (): Promise => { + aliasToColumn[col.id] = async (): Promise => { return { // convert from DB timezone to UTC builder: knex.raw( @@ -659,7 +663,7 @@ async function _formulaQueryBuilder( refCol.dt !== 'timestamp with time zone' && refCol.dt !== 'timestamptz' ) { - aliasToColumn[refCol.id] = async (): Promise => { + aliasToColumn[col.id] = async (): Promise => { return { // convert from DB timezone to UTC builder: knex @@ -675,7 +679,7 @@ async function _formulaQueryBuilder( refCol.dt !== 'datetimeoffset' ) { // convert from DB timezone to UTC - aliasToColumn[refCol.id] = async (): Promise => { + aliasToColumn[col.id] = async (): Promise => { return { builder: knex.raw( `CONVERT(DATETIMEOFFSET, ?? AT TIME ZONE 'UTC')`, @@ -684,9 +688,10 @@ async function _formulaQueryBuilder( }; }; } else { - aliasToColumn[refCol.id] = () => + aliasToColumn[col.id] = () => Promise.resolve({ builder: refCol.column_name }); } + aliasToColumn[refCol.id] = aliasToColumn[col.id]; } break; case UITypes.User: