From a11cf7a90eff60dc1f2ed42c28d92ddd5bdd7914 Mon Sep 17 00:00:00 2001 From: advplyr Date: Thu, 16 May 2024 14:56:19 -0500 Subject: [PATCH] Fix:Book library author name sort order with multi-author books #2859 --- server/utils/queries/libraryItemsBookFilters.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/utils/queries/libraryItemsBookFilters.js b/server/utils/queries/libraryItemsBookFilters.js index 35eb2de2..f88c6385 100644 --- a/server/utils/queries/libraryItemsBookFilters.js +++ b/server/utils/queries/libraryItemsBookFilters.js @@ -360,11 +360,11 @@ module.exports = { let bookAttributes = null if (sortBy === 'media.metadata.authorNameLF') { bookAttributes = { - include: [[Sequelize.literal(`(SELECT group_concat(a.lastFirst, ", ") FROM authors AS a, bookAuthors as ba WHERE ba.authorId = a.id AND ba.bookId = book.id)`), 'author_name']] + include: [[Sequelize.literal(`(SELECT group_concat(lastFirst, ", ") FROM (SELECT a.lastFirst FROM authors AS a, bookAuthors as ba WHERE ba.authorId = a.id AND ba.bookId = book.id ORDER BY ba.createdAt ASC))`), 'author_name']] } } else if (sortBy === 'media.metadata.authorName') { bookAttributes = { - include: [[Sequelize.literal(`(SELECT group_concat(a.name, ", ") FROM authors AS a, bookAuthors as ba WHERE ba.authorId = a.id AND ba.bookId = book.id)`), 'author_name']] + include: [[Sequelize.literal(`(SELECT group_concat(name, ", ") FROM (SELECT a.name FROM authors AS a, bookAuthors as ba WHERE ba.authorId = a.id AND ba.bookId = book.id ORDER BY ba.createdAt ASC))`), 'author_name']] } }