Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Specifying query columns carries over
  • I have a controller that does multiple queries using the same model. The first query looks like this:

            $tickets = Ticket::query(array('id'))->where('location_id', 'IN', \Arr::pluck($result, 'id'))->get();

    It works fine. However, when I try to do an additional query:

    $tickets = Ticket::query()->where('client_id', 20)->get();

    The result only contains the `id` column. Is this the intended functionality? Do I have to do something like Ticket::query('*') to fetch all of the columns?
  • HarroHarro
    Accepted Answer
    The ORM caches the results of all queries, as soon as the primary key is part of the result.

    Downside of that is that if you select a partial column list, you will miss data on subsequent queries, because the result is fetched from cache.

    This is not really by design, selecting a subset of columns was never part of the design, and introducing that has led to this side-effect. Passing a select() won't help, because if the primary key is in cache, the database will not be used.

    1.6 has a method from_cache(), that you can use:

    $tickets = Ticket::query()->from-cache(false)->where('client_id', 20)->get();

    It will disable the use of the result cache for this query.
  • Thanks! It looks like the simplest solution is to just not specify the "id" column in the first query.
  • Absolutely right.

    Given the fact the ORM isn't meant to handle large volumes of data, there is no real penalty for fetching all columns.

Howdy, Stranger!

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

In this Discussion