diff --git a/packages/core/database/src/options-parser.ts b/packages/core/database/src/options-parser.ts index c91df65456..806d69074f 100644 --- a/packages/core/database/src/options-parser.ts +++ b/packages/core/database/src/options-parser.ts @@ -138,10 +138,10 @@ export class OptionsParser { sort = sort.split(','); } - let defaultSortField = this.model.primaryKeyAttribute; + let defaultSortField: Array | string = this.model.primaryKeyAttribute; - if (Array.isArray(this.collection.filterTargetKey) && this.collection.filterTargetKey.length == 1) { - defaultSortField = this.collection.filterTargetKey[0]; + if (Array.isArray(this.collection.filterTargetKey)) { + defaultSortField = this.collection.filterTargetKey; } if (!defaultSortField && this.collection.filterTargetKey && !Array.isArray(this.collection.filterTargetKey)) { @@ -149,8 +149,11 @@ export class OptionsParser { } if (defaultSortField && !this.options?.group) { - if (!sort.includes(defaultSortField)) { - sort.push(defaultSortField); + defaultSortField = lodash.castArray(defaultSortField); + for (const key of defaultSortField) { + if (!sort.includes(key)) { + sort.push(key); + } } }