From eccd2204619b3f12118d59c6a439004a2ed331e6 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Tue, 5 Jan 2021 14:06:20 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20error=20when=20deleting?= =?UTF-8?q?=20a=20member=20that=20has=20received=20a=20newsletter=20email?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes https://github.com/TryGhost/Ghost/issues/12493 - bumps `bookshelf-relations` to new version that allows for `hasMany` children to be kept when a parent record is destroyed - adds necessary config to the `Member.email_recipients` relationship to keep related records when a member is deleted --- core/server/models/member.js | 8 ++++++++ package.json | 2 +- yarn.lock | 8 ++++---- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/core/server/models/member.js b/core/server/models/member.js index 3b273d65f2..7d1eb1b4d4 100644 --- a/core/server/models/member.js +++ b/core/server/models/member.js @@ -19,6 +19,14 @@ const Member = ghostBookshelf.Model.extend({ relationships: ['labels', 'stripeCustomers', 'email_recipients'], + // do not delete email_recipients records when a member is destroyed. Recipient + // records are used for analytics and historical records + relationshipConfig: { + email_recipients: { + destroyRelated: false + } + }, + relationshipBelongsTo: { labels: 'labels', stripeCustomers: 'members_stripe_customers', diff --git a/package.json b/package.json index e93c68b404..7d49939a9b 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "bluebird": "3.7.2", "body-parser": "1.19.0", "bookshelf": "0.15.2", - "bookshelf-relations": "1.3.2", + "bookshelf-relations": "1.4.0", "brute-knex": "4.0.1", "bson-objectid": "1.3.1", "bthreads": "0.5.1", diff --git a/yarn.lock b/yarn.lock index 6585a0eb80..6a8806d46c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1366,10 +1366,10 @@ body@^5.1.0: raw-body "~1.1.0" safe-json-parse "~1.0.1" -bookshelf-relations@1.3.2: - version "1.3.2" - resolved "https://registry.yarnpkg.com/bookshelf-relations/-/bookshelf-relations-1.3.2.tgz#bceb0ab3b172b01a48a81eed16cd68446975515a" - integrity sha512-LrsWiO3kKfYCTGWxCVzFuEi/hIfukRz6n3KIcQqCFaAO/PmYxFtxarMGeVKDpL/hm1BudksrK7S9vXmkfgv8eQ== +bookshelf-relations@1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/bookshelf-relations/-/bookshelf-relations-1.4.0.tgz#88f7f53b0417d99a6a2a53b386e71fd0b113df6e" + integrity sha512-l/tf4ouBw7vLmqYdyV7MvdZKROr3Cc1+7qdVF2ejqeluZ5vDxomrFH/0ftOe7c1RdJdSSxdkuZikf5QGfjqFiw== dependencies: bluebird "3.7.2" ghost-ignition "4.1.0"