Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Problem with multiple query on a model
  • Hi,

    I have a model with many attributs (id, name, city, zipcode, ...).

    If i do this query :

            $q = \Model_Pageadherent::query()
                    ->rows_limit(999)
                    ->select('city')
                    ->where('zipcode', '=', '97420')
                    ->group_by('city')
                    ->order_by('city', 'ASC')->get();

    And after this i do :

    $adhs = \Model_Pageadherent::query()->where('zipcode', '97420')->get();

    My model in $adhs contains just the attribute "id" and "city" because it keep the select('city') in the previous query.

    It's normal ? Or a bug ?
  • Ok i think is the cache. With from_cache(false) it's work.
  • HarroHarro
    Accepted Answer
    select() is not really supported in ORM.

    ORM caches query results, so if you run a second query for a PK you have already, you get the object from cache back.

    Partial selects create incomplete objects (properties missing), which is potentially very dangerous when you start manipulating them (or saving them), and should be avoided.
  • Thanks for your answer, i understand better!
  • Hello Harro!
    I blieve that this thread is approprited place for my question.

    I'm curious is there a plan is to create standalone cache for such partial-selected objects?
  • No, there isn't.

    But for v2 we're going to completely rewrite the ORM. If you have idea's about features or implementation, create an issue here: https://github.com/fuelphp/orm/issues so it can be discussed.
  • Thanks for your answer!

Howdy, Stranger!

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

In this Discussion