Skip to content

Commit 184b6e4

Browse files
committed
fix: use correct sort for negative take
1 parent 16c196a commit 184b6e4

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

packages/orm/src/client/crud/dialects/lateral-join-dialect-base.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,16 @@ export abstract class LateralJoinDialectBase<Schema extends SchemaDef> extends B
213213
}
214214

215215
const expr = this.fieldRef(model, field, modelAlias);
216+
let sort = typeof value === 'string' ? value : value.sort;
217+
if (payload.take !== undefined && payload.take < 0) {
218+
// negative `take` requires negated sorting, and the result order
219+
// will be corrected during post-read processing
220+
sort = this.negateSort(sort, true);
221+
}
216222
if (typeof value === 'string') {
217-
items.push({ expr, sort: value });
223+
items.push({ expr, sort });
218224
} else {
219-
items.push({ expr, sort: value.sort, nulls: value.nulls });
225+
items.push({ expr, sort, nulls: value.nulls });
220226
}
221227
}
222228
}

0 commit comments

Comments
 (0)