Browse Source

feat: improved bt handling

Signed-off-by: mertmit <mertmit99@gmail.com>
feat/export-nest-dir-restructure
mertmit 2 years ago committed by starbirdtech383
parent
commit
32bc001596
  1. 49
      packages/nocodb-nest/src/modules/jobs/export-import/export.service.ts

49
packages/nocodb-nest/src/modules/jobs/export-import/export.service.ts

@ -258,22 +258,27 @@ export class ExportService {
const pkMap = new Map<string, string>(); const pkMap = new Map<string, string>();
const fields = model.columns const fields = model.columns
.filter((c) => c.colOptions?.type !== 'hm' && c.colOptions?.type !== 'mm') .filter((c) => c.uidt !== UITypes.LinkToAnotherRecord)
.map((c) => c.title) .map((c) => c.title)
.join(','); .join(',');
const btMap = new Map<string, string>();
for (const column of model.columns.filter( for (const column of model.columns.filter(
(col) => (col) =>
col.uidt === UITypes.LinkToAnotherRecord && col.uidt === UITypes.LinkToAnotherRecord &&
col.colOptions?.type !== 'hm', col.colOptions?.type === 'bt',
)) { )) {
const relatedTable = await ( await column.getColOptions();
(await column.getColOptions()) as LinkToAnotherRecordColumn const fkCol = model.columns.find(
).getRelatedTable(); (c) => c.id === column.colOptions?.fk_child_column_id,
);
await relatedTable.getColumns(); if (fkCol) {
btMap.set(
pkMap.set(column.id, relatedTable.primaryKey.title); fkCol.id,
`${column.project_id}::${column.base_id}::${column.fk_model_id}::${column.id}`,
);
}
} }
const mmColumns = model.columns.filter( const mmColumns = model.columns.filter(
@ -286,12 +291,6 @@ export class ExportService {
dataStream.setEncoding('utf8'); dataStream.setEncoding('utf8');
const baseModel = await Model.getBaseModelSQL({
id: model.id,
viewId: view?.id,
dbDriver: await NcConnectionMgrv2.get(base),
});
const formatData = (data: any) => { const formatData = (data: any) => {
for (const row of data) { for (const row of data) {
for (const [k, v] of Object.entries(row)) { for (const [k, v] of Object.entries(row)) {
@ -299,16 +298,11 @@ export class ExportService {
if (col) { if (col) {
const colId = `${col.project_id}::${col.base_id}::${col.fk_model_id}::${col.id}`; const colId = `${col.project_id}::${col.base_id}::${col.fk_model_id}::${col.id}`;
switch (col.uidt) { switch (col.uidt) {
case UITypes.LinkToAnotherRecord: case UITypes.ForeignKey:
{ {
if (col.system || col.colOptions.type !== 'bt') break; if (btMap.has(col.id)) {
row[btMap.get(col.id)] = v;
if (v) { delete row[k];
for (const [k, val] of Object.entries(v)) {
if (k === pkMap.get(col.id)) {
row[colId] = val;
}
}
} }
} }
break; break;
@ -319,7 +313,6 @@ export class ExportService {
row[colId] = v; row[colId] = v;
} }
break; break;
case UITypes.ForeignKey:
case UITypes.Formula: case UITypes.Formula:
case UITypes.Lookup: case UITypes.Lookup:
case UITypes.Rollup: case UITypes.Rollup:
@ -338,6 +331,12 @@ export class ExportService {
return { data }; return { data };
}; };
const baseModel = await Model.getBaseModelSQL({
id: model.id,
viewId: view?.id,
dbDriver: await NcConnectionMgrv2.get(base),
});
const limit = 200; const limit = 200;
const offset = 0; const offset = 0;

Loading…
Cancel
Save