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,
});
}
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) {

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

@ -675,44 +675,6 @@ export default class Column<T = any> 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

24
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.`,
);
});
}
}

Loading…
Cancel
Save