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;