mirror of
https://github.com/directus/directus.git
synced 2026-01-23 22:48:25 -05:00
Cleanup one_allowed_collections field on collection delete (#6167)
Fixes #6161
This commit is contained in:
@@ -399,6 +399,19 @@ export class CollectionsService {
|
||||
}
|
||||
}
|
||||
|
||||
const m2aRelationsThatIncludeThisCollection = this.schema.relations.filter((relation) => {
|
||||
return relation.meta?.one_allowed_collections?.includes(collectionKey);
|
||||
});
|
||||
|
||||
for (const relation of m2aRelationsThatIncludeThisCollection) {
|
||||
const newAllowedCollections = relation
|
||||
.meta!.one_allowed_collections!.filter((collection) => collectionKey !== collection)
|
||||
.join(',');
|
||||
await trx('directus_relations')
|
||||
.update({ one_allowed_collections: newAllowedCollections })
|
||||
.where({ id: relation.meta!.id });
|
||||
}
|
||||
|
||||
await collectionItemsService.deleteOne(collectionKey);
|
||||
await trx.schema.dropTable(collectionKey);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user