Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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 ?



83.4k
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: http://docs.phalconphp.com/en/latest/reference/models.html#hydration-modes

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