From 211de82a8dd4e6ccbd448f764caa2e2d1116fbe7 Mon Sep 17 00:00:00 2001 From: Simon Backx Date: Tue, 3 Jan 2023 09:43:41 +0100 Subject: [PATCH] Fixed random test failure due to member newsletter ordering (#16024) fixes https://github.com/TryGhost/Team/issues/2365 The newsletters relation of a member was not sorted. This is fixed now, so we have consistent results in the test snapshots. --- ghost/core/core/server/models/member.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ghost/core/core/server/models/member.js b/ghost/core/core/server/models/member.js index 9e2f1671a8..c2af64658c 100644 --- a/ghost/core/core/server/models/member.js +++ b/ghost/core/core/server/models/member.js @@ -50,7 +50,7 @@ const Member = ghostBookshelf.Model.extend({ replacement: 'emails.post_id', // Currently we cannot expand on values such as null or a string in mongo-knex // But the line below is essentially the same as: `email_recipients.opened_at:-null` - expansion: 'email_recipients.opened_at:>=0' + expansion: 'email_recipients.opened_at:>=0' }]; }, @@ -165,6 +165,7 @@ const Member = ghostBookshelf.Model.extend({ newsletters() { return this.belongsToMany('Newsletter', 'members_newsletters', 'member_id', 'newsletter_id') + .query('orderBy', 'newsletters.sort_order', 'ASC') .query((qb) => { // avoids bookshelf adding a `DISTINCT` to the query // we know the result set will already be unique and DISTINCT hurts query performance