Browse Source

fix: handle when HM lookups to BT

pull/8855/head
Pranav C 5 months ago
parent
commit
34da8a8d0d
  1. 24
      packages/nocodb/src/db/BaseModelSqlv2.ts

24
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 = {};
let tempObj: Record<string, any> | Record<string, any>[];
// 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;

Loading…
Cancel
Save