Browse Source

Update packages/nocodb/src/db/BaseModelSqlv2.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
pull/8855/head
Pranav C 6 months ago committed by GitHub
parent
commit
757b06c349
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 24
      packages/nocodb/src/db/BaseModelSqlv2.ts

24
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -6025,29 +6025,19 @@ class BaseModelSqlv2 {
if (alias) {
if (btMap[key]) {
if (value && typeof value === 'object') {
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 = {};
function transformObject(value, idToAliasMap) {
let result = {};
Object.entries(value).forEach(([k, v]) => {
const btAlias = idToAliasMap[k];
if (btAlias) {
tempObj[btAlias] = v;
result[btAlias] = v;
}
});
return result;
}
let tempObj = Array.isArray(value) ? value.map(arrVal => transformObject(arrVal, idToAliasMap)) : transformObject(value, idToAliasMap);
item[alias] = tempObj;
item[alias] = tempObj;
} else {
item[alias] = value;

Loading…
Cancel
Save