Browse Source

fix: show error while deleting column used in a custom relation

pull/8367/head
Pranav C 5 months ago
parent
commit
8e62601a2e
  1. 2
      packages/nocodb/src/db/BaseModelSqlv2.ts
  2. 42
      packages/nocodb/src/services/columns.service.ts
  3. 2
      packages/nocodb/src/services/tables.service.ts

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

@ -6936,7 +6936,7 @@ class BaseModelSqlv2 {
delete item[key]; delete item[key];
} }
}); });
});k });
return data; return data;
} }

42
packages/nocodb/src/services/columns.service.ts

@ -64,6 +64,7 @@ import Noco from '~/Noco';
import NcConnectionMgrv2 from '~/utils/common/NcConnectionMgrv2'; import NcConnectionMgrv2 from '~/utils/common/NcConnectionMgrv2';
import { MetaTable } from '~/utils/globals'; import { MetaTable } from '~/utils/globals';
import { MetaService } from '~/meta/meta.service'; import { MetaService } from '~/meta/meta.service';
import { parseMetaProp } from '~/utils/modelUtils';
// todo: move // todo: move
export enum Altered { export enum Altered {
@ -2099,6 +2100,47 @@ export class ColumnsService {
ProjectMgrv2.getSqlMgr(context, { id: source.base_id }, ncMeta), ProjectMgrv2.getSqlMgr(context, { id: source.base_id }, ncMeta),
); );
// check column association with any custom links or LTAR
if (!isVirtualCol(col)) {
const links = await ncMeta.metaList2(
null,
null,
MetaTable.COL_RELATIONS,
{
xcCondition: {
_or: [
{ fk_child_column_id: { eq: id } },
{ fk_parent_column_id: { eq: id } },
{ fk_mm_child_column_id: { eq: id } },
{ fk_mm_parent_column_id: { eq: id } },
],
},
},
);
// if custom relation then delete
if (
links?.length &&
links.every((lk) => {
try {
return parseMetaProp(lk)?.custom;
} catch {
// ignore
}
})
) {
const linkCol = await Column.get(links[0].fk_column_id, ncMeta);
const table = await linkCol.getModel(ncMeta);
NcError.columnAssociatedWithLink(
`Column is associated with custom link ${
linkCol.title || linkCol.column_name
} (${
table.title || table.table_name
}). Please delete the link column first.`,
);
}
}
/** /**
* @Note: When using 'falls through to default' cases in a switch statement, * @Note: When using 'falls through to default' cases in a switch statement,
* it is crucial to place them after cases with break statements. * it is crucial to place them after cases with break statements.

2
packages/nocodb/src/services/tables.service.ts

@ -238,7 +238,7 @@ export class TablesService {
}, },
); );
if (relations.leghth) { if (relations.length) {
const relCol = await Column.get(relations[0].fk_column_id); const relCol = await Column.get(relations[0].fk_column_id);
const relTable = await Model.get(relCol.fk_model_id); const relTable = await Model.get(relCol.fk_model_id);
NcError.badRequest( NcError.badRequest(

Loading…
Cancel
Save