Cleanup one_allowed_collections field on collection delete (#6167)

Fixes #6161
This commit is contained in:
Rijk van Zanten
2021-06-09 17:02:47 -04:00
committed by GitHub
parent b5abb0fb20
commit fb908efe8f

View File

@@ -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);
});