From f00a38737b780dbc9c0739c87cd51c367c2b3bc8 Mon Sep 17 00:00:00 2001 From: rijkvanzanten Date: Tue, 12 Jan 2021 16:23:30 -0500 Subject: [PATCH] Delete collections item first Fixes #3593 --- api/src/services/collections.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/api/src/services/collections.ts b/api/src/services/collections.ts index d278dd7101..d1736c924c 100644 --- a/api/src/services/collections.ts +++ b/api/src/services/collections.ts @@ -260,6 +260,12 @@ export class CollectionsService { throw new ForbiddenException('Only admins can perform this action.'); } + const collectionItemsService = new ItemsService('directus_collections', { + knex: this.knex, + accountability: this.accountability, + schema: this.schema, + }); + const fieldsService = new FieldsService({ knex: this.knex, accountability: this.accountability, @@ -276,6 +282,8 @@ export class CollectionsService { } } + await collectionItemsService.delete(collectionKeys); + await this.knex('directus_fields').delete().whereIn('collection', collectionKeys); await this.knex('directus_presets').delete().whereIn('collection', collectionKeys); await this.knex('directus_revisions').delete().whereIn('collection', collectionKeys); @@ -305,14 +313,6 @@ export class CollectionsService { } } - const collectionItemsService = new ItemsService('directus_collections', { - knex: this.knex, - accountability: this.accountability, - schema: this.schema, - }); - - await collectionItemsService.delete(collectionKeys); - for (const collectionKey of collectionKeys) { await this.knex.schema.dropTable(collectionKey); }