From 34da8a8d0dc6ccac434c9c75198fb97ea2cf9adf Mon Sep 17 00:00:00 2001 From: Pranav C Date: Tue, 25 Jun 2024 11:25:34 +0000 Subject: [PATCH 1/4] fix: handle when HM lookups to BT --- packages/nocodb/src/db/BaseModelSqlv2.ts | 36 ++++++++++++++++++------ 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index c614230251..7f119be7d0 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -5973,7 +5973,11 @@ class BaseModelSqlv2 { ); if (btData) { if (typeof btData[col.id] === 'object') { - for (const k of Object.keys(btData[col.id])) { + for (const k of Object.keys( + Array.isArray(btData[col.id]) + ? btData[col.id][0] || {} + : btData[col.id], + )) { const btAlias = idToAliasMap[k]; if (!btAlias) { idToAliasPromiseMap[k] = Column.get(this.context, { @@ -6010,13 +6014,29 @@ class BaseModelSqlv2 { if (alias) { if (btMap[key]) { if (value && typeof value === 'object') { - const tempObj = {}; - Object.entries(value).forEach(([k, v]) => { - const btAlias = idToAliasMap[k]; - if (btAlias) { - tempObj[btAlias] = v; - } - }); + let tempObj: Record | Record[]; + + // if array of values then handle by using map, it will be an array when it's HM Lookup to a BT + if (Array.isArray(value)) { + tempObj = value.map((arrVal) => { + const obj = {}; + Object.entries(arrVal).forEach(([k, val]) => { + const btAlias = idToAliasMap[k]; + if (btAlias) { + obj[btAlias] = val; + } + }); + return obj; + }); + } else { + tempObj = {}; + Object.entries(value).forEach(([k, v]) => { + const btAlias = idToAliasMap[k]; + if (btAlias) { + tempObj[btAlias] = v; + } + }); + } item[alias] = tempObj; } else { item[alias] = value; From 9d50338e9e4505591320b0bef8fda42e4728a0eb Mon Sep 17 00:00:00 2001 From: Pranav C Date: Tue, 25 Jun 2024 11:25:34 +0000 Subject: [PATCH 2/4] fix: handle exceptions gracefully --- packages/nocodb/src/db/BaseModelSqlv2.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index 7f119be7d0..278a5a7b62 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -5982,9 +5982,13 @@ class BaseModelSqlv2 { if (!btAlias) { idToAliasPromiseMap[k] = Column.get(this.context, { colId: k, - }).then((col) => { - return col.title; - }); + }) + .then((col) => { + return col.title; + }) + .catch((e) => { + return Promise.resolve(e); + }); } } } else { @@ -5993,9 +5997,13 @@ class BaseModelSqlv2 { if (!btAlias) { idToAliasPromiseMap[col.id] = Column.get(this.context, { colId: col.id, - }).then((col) => { - return col.title; - }); + }) + .then((col) => { + return col.title; + }) + .catch((e) => { + return Promise.resolve(e); + }); } } } @@ -6006,6 +6014,9 @@ class BaseModelSqlv2 { for (const k of Object.keys(idToAliasPromiseMap)) { idToAliasMap[k] = await idToAliasPromiseMap[k]; + if ((idToAliasMap[k] as unknown) instanceof Error) { + throw idToAliasMap[k]; + } } data.forEach((item) => { From 2df06a50909b372187c72371bd217453986ca22e Mon Sep 17 00:00:00 2001 From: Raju Udava <86527202+dstala@users.noreply.github.com> Date: Tue, 25 Jun 2024 11:25:34 +0000 Subject: [PATCH 3/4] test: fix bt lookup --- packages/nc-gui/components/virtual-cell/BelongsTo.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nc-gui/components/virtual-cell/BelongsTo.vue b/packages/nc-gui/components/virtual-cell/BelongsTo.vue index cbb0667c68..8f5cc35e58 100644 --- a/packages/nc-gui/components/virtual-cell/BelongsTo.vue +++ b/packages/nc-gui/components/virtual-cell/BelongsTo.vue @@ -88,7 +88,7 @@ watch(value, (next) => {
-
+