Skip to content

Commit

Permalink
Cleanup one_allowed_collections field on collection delete (directus#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rijkvanzanten authored Jun 9, 2021
1 parent b5abb0f commit fb908ef
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions api/src/services/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit fb908ef

Please sign in to comment.