diff --git a/packages/nocodb/src/helpers/catchError.ts b/packages/nocodb/src/helpers/catchError.ts index 8b2d683e11..b3e7619fa6 100644 --- a/packages/nocodb/src/helpers/catchError.ts +++ b/packages/nocodb/src/helpers/catchError.ts @@ -634,8 +634,8 @@ export class NcError { ...args, }); } - static columnAssociatedWithLink(id: string) { - throw new NcBaseErrorv2(NcErrorType.COLUMN_ASSOCIATED_WITH_LINK); + static columnAssociatedWithLink(_id: string, args: NcErrorArgs) { + throw new NcBaseErrorv2(NcErrorType.COLUMN_ASSOCIATED_WITH_LINK, args); } static baseNotFound(id: string, args?: NcErrorArgs) { diff --git a/packages/nocodb/src/models/Column.ts b/packages/nocodb/src/models/Column.ts index 473a10df3d..41588fc88f 100644 --- a/packages/nocodb/src/models/Column.ts +++ b/packages/nocodb/src/models/Column.ts @@ -675,44 +675,6 @@ export default class Column implements ColumnType { return; } - // 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.every((lk) => { - try { - return parseMetaProp(lk)?.custom; - } catch { - // ignore - } - }) - ) { - for (const link of links) { - await Column.delete(link.id, ncMeta); - } - } - - if (links.length) { - NcError.columnAssociatedWithLink(id); - } - } - // todo: or instead of delete reset related foreign key value to null and handle in BaseModel // get qr code columns and delete diff --git a/packages/nocodb/src/services/columns.service.ts b/packages/nocodb/src/services/columns.service.ts index 7b537a89f9..365ad5c505 100644 --- a/packages/nocodb/src/services/columns.service.ts +++ b/packages/nocodb/src/services/columns.service.ts @@ -2119,25 +2119,19 @@ export class ColumnsService { ); // 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); + if (links?.length) { + const linkCol = await Column.get( + { colId: links[0].fk_column_id }, + ncMeta, + ); const table = await linkCol.getModel(ncMeta); - NcError.columnAssociatedWithLink( - `Column is associated with custom link ${ + NcError.columnAssociatedWithLink(column.id, { + customMessage: `Column is associated with custom link '${ linkCol.title || linkCol.column_name - } (${ + }' (${ table.title || table.table_name }). Please delete the link column first.`, - ); + }); } }