From 44916b756b670ce4cea98fedfe1b4cd909de06ce Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Tue, 7 Apr 2020 10:35:22 +0200 Subject: [PATCH] fix(core): Fix deletion of Collections Closes #297. The error was due to a foreign key violation on the CollectionAsset. Fixed by adding a delete cascade to the CollectionAsset BREAKING CHANGE: The CollectionAsset entity had a cascade delete defined, which will require a DB migration. --- packages/core/e2e/collection.e2e-spec.ts | 2 ++ packages/core/src/entity/collection/collection-asset.entity.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/core/e2e/collection.e2e-spec.ts b/packages/core/e2e/collection.e2e-spec.ts index 6a1e99046b..1fddc0a4f3 100644 --- a/packages/core/e2e/collection.e2e-spec.ts +++ b/packages/core/e2e/collection.e2e-spec.ts @@ -486,6 +486,7 @@ describe('Collection resolver', () => { translations: [ { languageCode: LanguageCode.en, name: 'Delete Me Parent', description: '' }, ], + assetIds: ['T_1'], }, }, ); @@ -500,6 +501,7 @@ describe('Collection resolver', () => { { languageCode: LanguageCode.en, name: 'Delete Me Child', description: '' }, ], parentId: collectionToDeleteParent.id, + assetIds: ['T_2'], }, }, ); diff --git a/packages/core/src/entity/collection/collection-asset.entity.ts b/packages/core/src/entity/collection/collection-asset.entity.ts index 66c7c88a52..b2f9573d7b 100644 --- a/packages/core/src/entity/collection/collection-asset.entity.ts +++ b/packages/core/src/entity/collection/collection-asset.entity.ts @@ -13,6 +13,6 @@ export class CollectionAsset extends OrderableAsset { @Column() collectionId: ID; - @ManyToOne(type => Collection, collection => collection.assets) + @ManyToOne((type) => Collection, (collection) => collection.assets, { onDelete: 'CASCADE' }) collection: Collection; }