I am trying to do pagination and with sorting. The problem, is that it only sorts the result after it generated a result. It's a bit hard to explain so I will show the code here (I will use paste bin for easier reading.)
I am curious why instead of FROM `project` it did another query. It ruins the pagination as it does it in the query instead of outside beside the ORDER BY. My fix is to not related the user table and project table and just do separate queries.
This has been explained here several times. The ORM uses a subquery to make sure results are consistent when you include relations, even when you apply limits.
Since ORM caches objects, once you have fetched an incomplete result, you can't access the rest anymore. Which means if you start manipulating related objects, you end up with an inconsistent database.
For read-only purposes, like pagination, use rows_limit() and rows_offset(), like it says in the docs.