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.

[HELP ME]registerNamespaceAlias not to play a role

<?php
use Phalcon\Mvc\Model\Manager as ModelsManager;
...

$di->set(
    'modelsManager',
    function () {
        $modelsManager = new ModelsManager();
        $modelsManager->registerNamespaceAlias(
            'm',
            'Platform\Models\Entities\Order'
        );
        return $modelsManager;
    }
);

Model

<?php
namespace Platform\Models\Entities;

class Order extends \Phalcon\Mvc\Model
{
}
<?php
namespace Platform\Models\Entities;

class Business extends \Phalcon\Mvc\Model
{
}

Controller

<?php
$this->modelsManager->executeQuery('SELECT r.* FROM m:Order AS r JOIN m:Business AS b');

error

Syntax error, unexpected token ORDER, near to ' AS r JOIN m:Business AS b', when parsing: SELECT r.* FROM m:Order AS r JOIN m:Business AS b (49)



33.7k
Accepted
answer
edited Jul '15

It's because ORDER is a PHQL/SQL reserved word, you have to escape it:

$this->modelsManager->executeQuery('SELECT r.* FROM [m:Order] AS r JOIN m:Business AS b');

https://docs.phalconphp.com/en/latest/reference/phql.html#escaping-reserved-words

edited Jul '15

thanks