From 27bfa30f97cd5313f9d785f09b04ba593d9442be Mon Sep 17 00:00:00 2001 From: "Fabien \"egg\" O'Carroll" Date: Wed, 23 Aug 2023 13:06:16 +0700 Subject: [PATCH] Handled our forced null conversion in bookshelf refs https://github.com/TryGhost/Arch/issues/47 We've configured bookshelf to force empty strings to null, but this is undesired behaviour here, so unfortunately we have to leak some business logic into the repository. This needs to be done to correctly support our filter validation logic. --- .../services/collections/BookshelfCollectionsRepository.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ghost/core/core/server/services/collections/BookshelfCollectionsRepository.js b/ghost/core/core/server/services/collections/BookshelfCollectionsRepository.js index b76c004b38..7a1b9a3904 100644 --- a/ghost/core/core/server/services/collections/BookshelfCollectionsRepository.js +++ b/ghost/core/core/server/services/collections/BookshelfCollectionsRepository.js @@ -66,13 +66,17 @@ module.exports = class BookshelfCollectionsRepository { #modelToCollection(model) { const json = model.toJSON(); + let filter = json.filter; + if (json.type === 'automatic' && typeof filter !== 'string') { + filter = ''; + } return Collection.create({ id: json.id, slug: json.slug, title: json.title, description: json.description, - filter: json.filter, + filter: filter, type: json.type, featureImage: json.feature_image, posts: json.collectionPosts.map(collectionPost => collectionPost.post_id),