I tried to reproduce your issue with the following code:
<?php
namespace Some;
use Phalcon\DI,
Phalcon\Db\Column,
Phalcon\Mvc\Model,
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 Model
{
}
class RobotsParts extends Model
{
}
$rows = $modelsManager->createBuilder()
->columns('Some\RobotsParts.id, Some\Robots.name')
->from('Some\RobotsParts')
->join('Some\Robots')
->where('Some\RobotsParts.robots_id = :robots_id: AND Some\Robots.type = :type:',
array('robots_id' => 1, 'type' => 'mechanical')
)
->orderBy('Some\Robots.name')
->getQuery()
->execute();
foreach ($rows as $row) {
echo $row->id, PHP_EOL;
echo $row->name, PHP_EOL;
}
And it shows:
$ php c.php
SELECT `robots_parts`.`id` AS `id`, `robots`.`name` AS `name` FROM `robots_parts` INNER JOIN `robots` WHERE `robots_parts`.`robots_id` = :robots_id AND `robots`.`type` = :type ORDER BY `robots`.`name`
3
Astro Boy
2
Astro Boy
1
Astro Boy
3
Robotina
2
Robotina
1
Robotina