diff --git a/ving/record/VingRecord.mjs b/ving/record/VingRecord.mjs index eeaa600a..0879baa5 100644 --- a/ving/record/VingRecord.mjs +++ b/ving/record/VingRecord.mjs @@ -855,12 +855,19 @@ export class VingKind { where ) { const sortMethod = (params.sortOrder == 'desc') ? desc : asc; - let orderBy = [sortMethod(this.table.createdAt)]; + let orderBy = [sortMethod(this.table.createdAt), sortMethod(this.table.id)]; if (params.sortBy) { const cols = []; + let hasIdSortField = false; for (const field of params.sortBy) { + if (field == 'id') { + hasIdSortField = true; + } cols.push(sortMethod(this.table[field])); } + if (!hasIdSortField) { + cols.push(sortMethod(this.table.id)); + } orderBy = cols; } const itemsPerPage = isUndefined(params?.itemsPerPage) || params?.itemsPerPage > 100 || params?.itemsPerPage < 1 ? 10 : params.itemsPerPage;