fix: query table without primary key in mssql

This commit is contained in:
Chareice 2024-07-22 17:24:09 +08:00
parent 3cc5bdeccc
commit d9e972a0f3
No known key found for this signature in database

View File

@ -113,11 +113,15 @@ export class OptionsParser {
sort = sort.split(','); sort = sort.split(',');
} }
const primaryKeyField = this.model.primaryKeyAttribute; let defaultSortField = this.model.primaryKeyAttribute;
if (primaryKeyField && !this.options?.group) { if (!defaultSortField && this.collection.filterTargetKey) {
if (!sort.includes(primaryKeyField)) { defaultSortField = this.collection.filterTargetKey;
sort.push(primaryKeyField); }
if (defaultSortField && !this.options?.group) {
if (!sort.includes(defaultSortField)) {
sort.push(defaultSortField);
} }
} }