We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Why object returns me everything ?

Hi all

I made a query like that :

$selectSubcata = $this->modelsManager->createBuilder()
    ->columns("id,name,url")
    ->from("ItemsCategories")
    ->where("parent_id = :parent_id:",array("parent_id" => $val['id']))
    ->andWhere("active = 1")
    ->orderBy("list_order ASC");

    $a = $selectSubcata->getQuery()->execute();

When I print out $a via print_r i got everyting on site include databases, translations etc. And when I include it on array it's so big and it will be cuz of slowness ?

How can I return only data ? and is there a hydrate array on modelsManager ?



98.9k
Accepted
answer

When a resulset is print_r'd, it recursively prints references to objects that aren't part of the resulset such as the models manager, the DI etc. So seeing a big output does not mean the resulset actually have a big size or that it could make your application slow.

If you want to change the hydration mode, check this out: https://docs.phalcon.io/en/latest/reference/models.html#hydration-modes

I believe models have a dump() method that gives you just the relevant data for a model.