Browse Source

fix: remove leftover relations from col_relations on model delete

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/4761/head
mertmit 2 years ago
parent
commit
bd085facae
  1. 2
      packages/nocodb/src/lib/models/Base.ts
  2. 22
      packages/nocodb/src/lib/models/Model.ts

2
packages/nocodb/src/lib/models/Base.ts

@ -278,7 +278,7 @@ export default class Base implements BaseType {
ncMeta ncMeta
); );
for (const model of models) { for (const model of models) {
await model.delete(ncMeta); await model.delete(ncMeta, true);
} }
await NocoCache.deepDel( await NocoCache.deepDel(
CacheScope.BASE, CacheScope.BASE,

22
packages/nocodb/src/lib/models/Model.ts

@ -345,7 +345,7 @@ export default class Model implements TableType {
}); });
} }
async delete(ncMeta = Noco.ncMeta): Promise<boolean> { async delete(ncMeta = Noco.ncMeta, force = false): Promise<boolean> {
await Audit.deleteRowComments(this.id); await Audit.deleteRowComments(this.id);
for (const view of await this.getViews(true)) { for (const view of await this.getViews(true)) {
@ -391,6 +391,26 @@ export default class Model implements TableType {
} }
} }
if (force) {
const leftOverColumns = await ncMeta.metaList2(null, null, MetaTable.COL_RELATIONS, {
condition: {
fk_related_model_id: this.id,
},
});
for (const col of leftOverColumns) {
await NocoCache.deepDel(
CacheScope.COL_RELATION,
`${CacheScope.COL_RELATION}:${col.fk_column_id}`,
CacheDelDirection.CHILD_TO_PARENT
);
}
await ncMeta.metaDelete(null, null, MetaTable.COL_RELATIONS, {
fk_related_model_id: this.id,
});
}
await NocoCache.deepDel( await NocoCache.deepDel(
CacheScope.COLUMN, CacheScope.COLUMN,
`${CacheScope.COLUMN}:${this.id}`, `${CacheScope.COLUMN}:${this.id}`,

Loading…
Cancel
Save