mirror of
https://github.com/directus/directus.git
synced 2026-01-30 21:28:08 -05:00
Fix sort added by offset not removed for MSSQL (#17343)
This commit is contained in:
@@ -287,6 +287,9 @@ async function getDBQuery(
|
||||
}
|
||||
|
||||
if (sortRecords) {
|
||||
// Clears the order if any, eg: from MSSQL offset
|
||||
dbQuery.clear('order');
|
||||
|
||||
if (needsInnerQuery) {
|
||||
let orderByString = '';
|
||||
const orderByFields: Knex.Raw[] = [];
|
||||
@@ -326,9 +329,6 @@ async function getDBQuery(
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Clears the order if any, eg: from MSSQL offset
|
||||
dbQuery.clear('order');
|
||||
|
||||
sortRecords.map((sortRecord) => {
|
||||
if (sortRecord.column.includes('.')) {
|
||||
const [alias, field] = sortRecord.column.split('.');
|
||||
|
||||
@@ -39,10 +39,6 @@ export default function applyQuery(
|
||||
const aliasMap: AliasMap = options?.aliasMap ?? Object.create(null);
|
||||
let hasMultiRelationalFilter = false;
|
||||
|
||||
if (query.sort && !options?.isInnerQuery && !options?.hasMultiRelationalSort) {
|
||||
applySort(knex, schema, dbQuery, query.sort, collection, aliasMap);
|
||||
}
|
||||
|
||||
applyLimit(knex, dbQuery, query.limit);
|
||||
|
||||
if (query.offset) {
|
||||
@@ -50,7 +46,11 @@ export default function applyQuery(
|
||||
}
|
||||
|
||||
if (query.page && query.limit && query.limit !== -1) {
|
||||
dbQuery.offset(query.limit * (query.page - 1));
|
||||
applyOffset(knex, dbQuery, query.limit * (query.page - 1));
|
||||
}
|
||||
|
||||
if (query.sort && !options?.isInnerQuery && !options?.hasMultiRelationalSort) {
|
||||
applySort(knex, schema, dbQuery, query.sort, collection, aliasMap);
|
||||
}
|
||||
|
||||
if (query.search) {
|
||||
@@ -306,6 +306,9 @@ export function applySort(
|
||||
|
||||
if (returnRecords) return { sortRecords, hasMultiRelationalSort };
|
||||
|
||||
// Clears the order if any, eg: from MSSQL offset
|
||||
rootQuery.clear('order');
|
||||
|
||||
rootQuery.orderBy(sortRecords);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user