I tried to reproduce the issue and it seems to work:
<?php
use Phalcon\DI,
Phalcon\Db\Column,
Phalcon\Events\Manager as EventsManager,
Phalcon\Db\Adapter\Pdo\Mysql as Connection,
Phalcon\Mvc\Model\Manager as ModelsManager,
Phalcon\Mvc\Model\Metadata\Memory as ModelsMetaData;
$eventsManager = new EventsManager();
$di = new DI();
$connection = new Connection(array(
"host" => "localhost",
"username" => "root",
"password" => "",
"dbname" => "phalcon_test"
));
$connection->setEventsManager($eventsManager);
$eventsManager->attach('db',
function ($event, $connection) {
switch ($event->getType()) {
case 'beforeQuery':
echo $connection->getSqlStatement(), "\n";
break;
}
}
);
$modelsManager = new ModelsManager();
$modelsManager->setDi($di);
$di['db'] = $connection;
$di['modelsManager'] = $modelsManager;
$di['modelsMetadata'] = new ModelsMetadata();
class Robots extends Phalcon\Mvc\Model
{
}
class RobotsParts extends Phalcon\Mvc\Model
{
}
$phql = 'SELECT p.*, r.name FROM RobotsParts AS p LEFT JOIN Robots AS r ON p.robots_id = r.id WHERE r.id = ?0';
$rows = $modelsManager->executeQuery($phql, [1]);
foreach ($rows as $row) {
echo $row->name, PHP_EOL;
echo $row->p->parts_id, PHP_EOL;
}
php c.php
SELECT IF(COUNT(*)>0, 1 , 0) FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_NAME` = 'robots_parts' AND `TABLE_SCHEMA` = DATABASE()
DESCRIBE `robots_parts`
SELECT `p`.`id` AS `_p_id`, `p`.`robots_id` AS `_p_robots_id`, `p`.`parts_id` AS `_p_parts_id`, `r`.`name` AS `name` FROM `robots_parts` AS `p` LEFT JOIN `robots` AS `r` ON `p`.`robots_id` = `r`.`id` WHERE `r`.`id` = :0
Robotina
1
Robotina
2
Robotina
3