> Why would it be necessary then to do add the id of all the tables involved > in the query? My workaround is to specify the orderby using the id of one > of the involved tables and that already makes a big difference measured > against a query trying to use three or four fields when ordering. >
With a one-to-many relationship, the primary key of a given record from the first table may span more than one page, so there's no guarantee that you will get the same set of joined records on a given page when sorting by only that primary key. Even if you did happen to get the same set of records within a page, you could get different orderings of those records within the page on different visits. On the other hand, I believe if you order by the primary key of the second table (i.e., the "many" side of the one-to-many), you should always get the same order, as there will only be one occurrence of each primary key in the joined set. For a many-to-many relationship, you would need to sort on both primary keys. So, in your case, depending on the relationships between the tables, you may not need to sort on all primary keys, but it is not necessarily the case that you can just pick any single arbitrary primary key on which to sort. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.