Browse Source

Nc fix/duplicate link (#8422)

* fix: link duplicate (self reference)

* fix: avoid iterating source twice

* fix: duplicate self-referencing oo & hm

* fix: self-referencing mm for tables with bt

---------

Co-authored-by: Pranav C <pranavxc@gmail.com>
Co-authored-by: mertmit <mertmit99@gmail.com>
pull/8445/head
Raju Udava 8 months ago committed by GitHub
parent
commit
e4e9d2e7f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 7
      packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.processor.ts
  2. 32
      packages/nocodb/src/modules/jobs/jobs/export-import/import.service.ts

7
packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.processor.ts

@ -352,7 +352,7 @@ export class DuplicateProcessor {
.map((c) => c.id);
if (bts.length > 0) {
fields[md.id] = [md.primaryKey.id];
fields[md.id] = fields[md.id] ? fields[md.id] : [md.primaryKey.id];
fields[md.id].push(...bts);
}
}
@ -365,7 +365,10 @@ export class DuplicateProcessor {
destBase: source,
hrTime,
modelFieldIds: fields,
externalModels: [sourceModel, ...relatedModels],
externalModels: [
sourceModel,
...relatedModels.filter((m) => m.id !== sourceModel.id),
],
});
elapsedTime(hrTime, 'import model data', 'duplicateColumn');

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

@ -299,6 +299,11 @@ export class ImportService {
colOptions.fk_mm_model_id && a.id !== col.id,
);
// referencing the same model
if (colOptions.fk_related_model_id === modelData.id) {
continue;
}
for (const nColumn of childModel.columns) {
if (
nColumn?.colOptions?.fk_mm_model_id ===
@ -386,6 +391,33 @@ export class ImportService {
a.id !== col.id,
);
// referencing the same model
if (colOptions.fk_related_model_id === modelData.id) {
const counterRelationType =
colOptions.type === 'hm' ? 'bt' : 'oo';
const oldCol = childModel.columns.find(
(oColumn) =>
oColumn.colOptions?.fk_parent_column_id ===
getEntityIdentifier(colOptions.fk_parent_column_id) &&
oColumn.colOptions?.fk_child_column_id ===
getEntityIdentifier(colOptions.fk_child_column_id) &&
oColumn.colOptions?.type === counterRelationType,
);
const col = childModel.columns.find(
(nColumn) =>
nColumn.colOptions?.fk_parent_column_id ===
getIdOrExternalId(colOptions.fk_parent_column_id) &&
nColumn.colOptions?.fk_child_column_id ===
getIdOrExternalId(colOptions.fk_child_column_id) &&
nColumn.colOptions?.type === counterRelationType,
);
idMap.set(
`${oldCol.base_id}::${oldCol.source_id}::${oldCol.fk_model_id}::${oldCol.id}`,
col.id,
);
continue;
}
for (const nColumn of childModel.columns) {
if (
nColumn.id !== getIdOrExternalId(col.id) &&

Loading…
Cancel
Save