sea-orm
sea-orm copied to clipboard
`order_by_desc` not working with `cursor_by`
Description
Using order_by_desc is not working with cursor_by.
Steps to Reproduce
// Returned values are `by_asc` even if `by_desc` is specified
let result = thread::Entity::find()
.cursor_by(thread::Column::Id)
.order_by_desc(thread::Column::Id)
.after(10)
.before(0)
.limit(10)
.all(self.connection.as_ref())
.await?;
// Not working either
let result = thread::Entity::find()
.order_by_desc(thread::Column::Id)
.cursor_by(thread::Column::Id)
.order_by_desc(thread::Column::Id)
.after(10)
.before(0)
.limit(10)
.all(self.connection.as_ref())
.await?;
// This is working
let result = thread::Entity::find()
.order_by_desc(thread::Column::Id)
.all(self.connection.as_ref())
.await?;
Expected Behavior
Data sorted by desc.
Actual Behavior
order_by_desc is not applied.
Reproduces How Often
100%
Workarounds
None for the moment
Reproducible Example
https://github.com/SeaQL/sea-orm/pull/2377
Versions
│ └── sea-orm-migration v0.12.15
│ ├── sea-orm v0.12.15
│ │ ├── sea-orm-macros v0.12.15 (proc-macro)
│ │ │ ├── sea-bae v0.2.0 (proc-macro)
│ │ ├── sea-query v0.30.7
│ │ │ ├── sea-query-derive v0.4.1 (proc-macro)
│ │ ├── sea-query-binder v0.5.0
│ │ │ ├── sea-query v0.30.7 (*)
│ ├── sea-orm-cli v0.12.15
│ │ ├── sea-schema v0.14.2
│ │ │ ├── sea-query v0.30.7 (*)
│ │ │ └── sea-schema-derive v0.2.0 (proc-macro)
│ ├── sea-schema v0.14.2 (*)
├── sea-orm v0.12.15 (*)
This is because we currently implement the Cursor as a cross-database polyfill. Although Cursor implements the QueryOrder trait, its methods are effectively no-ops. To apply ordering on a Cursor correctly, you should use Cursor::asc and Cursor::desc, but this only supports simple sorting based on all cursor-by columns and does not support complex sorting rules.