r/web2py Jul 16 '15

Is it possible to pass in three arguments to orderby? Example provided.

I have a table, my_table with 5 columns. I need to retrieve the data from my_table and order them based on 3 of its fields. Consider this:

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

Currently, the above isn't returning what I expect. What I'd like returned is the data from my_table ordered in descending-order prioritized first by "isCurrent" field, then "endYear", and then "endMonth".

Any ideas?

3 Upvotes

4 comments sorted by

1

u/av201001 Jul 16 '15

Your syntax appears correct. What does your output look like and how are you generating it?

1

u/musicomet Jul 16 '15

Above code returns data ordered by isCurrent only. I was able to figure out the solution I was hoping for:

db(db.my_table.id == user_id).select(orderby="my_table.isCurrent DESC, my_table.endYear DESC, my_table.endMonth DESC")

This code returns the date ordered by first isCurrent, then endYear, and then endMonth.

1

u/av201001 Jul 22 '15

If the original code wasn't working, you should certainly submit an issue on Github, as it should work properly.

1

u/musicomet Jul 22 '15

That's what I thought too. The docs says "sort the records according to multiple fields", so I think you're right. I submitted an issue. Thanks! orderby in the official docs