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

Query builder and all columns select with JOIN

Hello) I have a code:

$items =  \Phalcon\DI::getDefault()->get('modelsManager')->createBuilder()
            ->addFrom('m:Invoices', 'i')
            ->leftJoin('m:users', 'u.id = i.user_id', 'u')
            ->columns('i.id, i.text, i.cost, i.status, DATE_FORMAT(i.date, "%d-%m-%Y") AS dt, u.name')
            ->limit($limit)->offset($offset)->orderBy($order)
            ->getQuery()->execute();

All works there, but if I want to select all items from first table:

->columns('i.*, u.name')

I get very strange object!!

$items[0]->name - return name from second table $items[0]->text - return error.

How can I receive the same result?

It groups the Invoices object in the alias "i":

foreach ($items as $item) {
      echo $item->name;
      echo $item->i->text;
}


1.3k

Thank you. Very strange code, but it works. I have no ideas, how make json from this code :(