Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Odd ORM Query Return
  • 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.)

    here is the ORM Model

    here is the SQL generated

    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.
  • HarroHarro
    Accepted Answer
    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.
  • Thanks. I just read that part in the docs.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion