Browse Source

fix: substitute column ids for LTAR (#8872)

* fix: move transformObject to root

* fix: substitue column ids for LTAR
pull/8878/head
Mert E 5 months ago committed by GitHub
parent
commit
eda4deab96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 60
      packages/nocodb/src/db/BaseModelSqlv2.ts

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

@ -176,6 +176,17 @@ export function replaceDynamicFieldWithValue(
return replaceWithValue; return replaceWithValue;
} }
function transformObject(value, idToAliasMap) {
const result = {};
Object.entries(value).forEach(([k, v]) => {
const btAlias = idToAliasMap[k];
if (btAlias) {
result[btAlias] = v;
}
});
return result;
}
/** /**
* Base class for models * Base class for models
* *
@ -5952,7 +5963,7 @@ class BaseModelSqlv2 {
const idToAliasMap: Record<string, string> = {}; const idToAliasMap: Record<string, string> = {};
const idToAliasPromiseMap: Record<string, Promise<string>> = {}; const idToAliasPromiseMap: Record<string, Promise<string>> = {};
const btMap: Record<string, boolean> = {}; const ltarMap: Record<string, boolean> = {};
modelColumns.forEach((col) => { modelColumns.forEach((col) => {
if (aliasColumns && col.id in aliasColumns) { if (aliasColumns && col.id in aliasColumns) {
@ -5962,24 +5973,20 @@ class BaseModelSqlv2 {
} }
idToAliasMap[col.id] = col.title; idToAliasMap[col.id] = col.title;
if ( if (col.uidt === UITypes.LinkToAnotherRecord) {
[RelationTypes.BELONGS_TO, RelationTypes.ONE_TO_ONE].includes( ltarMap[col.id] = true;
col.colOptions?.type, const linkData = Object.values(data).find(
)
) {
btMap[col.id] = true;
const btData = Object.values(data).find(
(d) => d[col.id] && Object.keys(d[col.id]), (d) => d[col.id] && Object.keys(d[col.id]),
); );
if (btData) { if (linkData) {
if (typeof btData[col.id] === 'object') { if (typeof linkData[col.id] === 'object') {
for (const k of Object.keys( for (const k of Object.keys(
Array.isArray(btData[col.id]) Array.isArray(linkData[col.id])
? btData[col.id][0] || {} ? linkData[col.id][0] || {}
: btData[col.id], : linkData[col.id],
)) { )) {
const btAlias = idToAliasMap[k]; const linkAlias = idToAliasMap[k];
if (!btAlias) { if (!linkAlias) {
idToAliasPromiseMap[k] = Column.get(this.context, { idToAliasPromiseMap[k] = Column.get(this.context, {
colId: k, colId: k,
}) })
@ -5993,8 +6000,8 @@ class BaseModelSqlv2 {
} }
} else { } else {
// Has Many BT // Has Many BT
const btAlias = idToAliasMap[col.id]; const linkAlias = idToAliasMap[col.id];
if (!btAlias) { if (!linkAlias) {
idToAliasPromiseMap[col.id] = Column.get(this.context, { idToAliasPromiseMap[col.id] = Column.get(this.context, {
colId: col.id, colId: col.id,
}) })
@ -6008,7 +6015,7 @@ class BaseModelSqlv2 {
} }
} }
} else { } else {
btMap[col.id] = false; ltarMap[col.id] = false;
} }
}); });
@ -6023,20 +6030,11 @@ class BaseModelSqlv2 {
Object.entries(item).forEach(([key, value]) => { Object.entries(item).forEach(([key, value]) => {
const alias = idToAliasMap[key]; const alias = idToAliasMap[key];
if (alias) { if (alias) {
if (btMap[key]) { if (ltarMap[key]) {
if (value && typeof value === 'object') { if (value && typeof value === 'object') {
function transformObject(value, idToAliasMap) { const tempObj = Array.isArray(value)
let result = {}; ? value.map((arrVal) => transformObject(arrVal, idToAliasMap))
Object.entries(value).forEach(([k, v]) => { : transformObject(value, idToAliasMap);
const btAlias = idToAliasMap[k];
if (btAlias) {
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;
item[alias] = tempObj; item[alias] = tempObj;
} else { } else {

Loading…
Cancel
Save