Browse Source

fix: column deletion correction

pull/8367/head
Pranav C 4 months ago
parent
commit
628c50edab
  1. 4
      packages/nocodb/src/helpers/catchError.ts
  2. 38
      packages/nocodb/src/models/Column.ts
  3. 24
      packages/nocodb/src/services/columns.service.ts

4
packages/nocodb/src/helpers/catchError.ts

@ -634,8 +634,8 @@ export class NcError {
...args, ...args,
}); });
} }
static columnAssociatedWithLink(id: string) { static columnAssociatedWithLink(_id: string, args: NcErrorArgs) {
throw new NcBaseErrorv2(NcErrorType.COLUMN_ASSOCIATED_WITH_LINK); throw new NcBaseErrorv2(NcErrorType.COLUMN_ASSOCIATED_WITH_LINK, args);
} }
static baseNotFound(id: string, args?: NcErrorArgs) { static baseNotFound(id: string, args?: NcErrorArgs) {

38
packages/nocodb/src/models/Column.ts

@ -675,44 +675,6 @@ export default class Column<T = any> implements ColumnType {
return; 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 // todo: or instead of delete reset related foreign key value to null and handle in BaseModel
// get qr code columns and delete // get qr code columns and delete

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

@ -2119,25 +2119,19 @@ export class ColumnsService {
); );
// if custom relation then delete // if custom relation then delete
if ( if (links?.length) {
links?.length && const linkCol = await Column.get(
links.every((lk) => { { colId: links[0].fk_column_id },
try { ncMeta,
return parseMetaProp(lk)?.custom; );
} catch {
// ignore
}
})
) {
const linkCol = await Column.get(links[0].fk_column_id, ncMeta);
const table = await linkCol.getModel(ncMeta); const table = await linkCol.getModel(ncMeta);
NcError.columnAssociatedWithLink( NcError.columnAssociatedWithLink(column.id, {
`Column is associated with custom link ${ customMessage: `Column is associated with custom link '${
linkCol.title || linkCol.column_name linkCol.title || linkCol.column_name
} (${ }' (${
table.title || table.table_name table.title || table.table_name
}). Please delete the link column first.`, }). Please delete the link column first.`,
); });
} }
} }

Loading…
Cancel
Save