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 Alias

i'm using the Phalcon's ::query() criteria and how can i use aliases ?

edited Jan '17
 $mm = $this->modelsManager->createBuilder()
            ->columns([
                'article_type_name' => 'typ.article_type_name',
                'origin_country_id',
                'destination_country_id'
            ])
            ->from(['vat' => 'm:ArticleVat', 'typ' => 'm:ArticleType']) //using implicit join with model namespace alias
            ->where('vat.article_type_id = typ.article_type_id')
            ->orderBy('vat.article_type_id') //DESC
            ->getQuery();

        $data = $mm->execute();

// Services definition
$di->setShared('modelsManager', function() {
    $mm = new \Phalcon\Mvc\Model\Manager();
    //Registers shorter aliases for namespaces in PHQL statements
    //public registerNamespaceAlias (mixed $alias, mixed $namespaceName)
    $mm->registerNamespaceAlias('m', __NAMESPACE__ . '\Models');
    return $mm;
});