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

Orderby: Sorting records according to multiple fields #1027

Closed
amir-beheshty opened this issue Jul 22, 2015 · 2 comments
Closed

Orderby: Sorting records according to multiple fields #1027

amir-beheshty opened this issue Jul 22, 2015 · 2 comments

Comments

@amir-beheshty
Copy link

orderby can accept multiple fields by concatenating them with a "|". See the official web2py docs:

However when I used this code:

db(db.my_table.id == user_id).select(orderby=~db.my_table.isCurrent | db.my_table.endYear | db.my_table.endMonth)

The return sorted the records based on isCurrent column only. The rest of the fields were ignored.

This code worked though:

db(db.my_table.id == user_id).select(orderby="my_table.isCurrent DESC, my_table.endYear DESC, my_table.endMonth DESC")
@cassiobotaro
Copy link
Contributor

Your query should be like db(db.my_table.id == user_id).select(orderby=~db.my_table.isCurrent | ~db.my_table.endYear | ~db.my_table.endMonth)

Tip: If you want to see the generated sql use _select db(db.my_table.id == user_id)._select(orderby=~db.my_table.isCurrent | ~db.my_table.endYear | ~db.my_table.endMonth) before run the code properly.

@amir-beheshty
Copy link
Author

I see. Thanks for clarifying that. I suppose a similar example would be useful for the official docs to devoid confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants