Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reversing unordered requests #342

Merged
merged 3 commits into from
Apr 26, 2018
Merged

Reversing unordered requests #342

merged 3 commits into from
Apr 26, 2018

Conversation

groue
Copy link
Owner

@groue groue commented Apr 26, 2018

This PR has the request.reversed() method do nothing unless an ordering was already applied:

// Unchanged: SELECT * FROM players ORDER BY score DESC
Player.order(Column("score")).reversed()

// New: SELECT * FROM players
Player.all().reversed()

In previous versions, reversed() would sort by descending rowId (inspiration drawn from ActiveRecord). Unfortunately, this made-up ordering is not guaranteed to be the exact opposite of the default SQLite ordering. And associations will soon need a stricter model of what "reversing" a request means.

So let's go back to basics:

If a SELECT statement that returns more than one row does not have an ORDER BY clause, the order in which the rows are returned is undefined.

Reversing an undefined order gives another undefined order.

@groue groue added this to the GRDB 3.0 milestone Apr 26, 2018
@groue groue mentioned this pull request Apr 26, 2018
29 tasks
@groue groue merged commit 497295a into GRDB3 Apr 26, 2018
@groue groue deleted the GRDB3-reversedCleanup branch April 27, 2018 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant