How to set an alias in Model :: query () in the Phalcon Framework

How to set an SQL alias for the Phalcon model. The alias () method does not exist.

An example of what I need:

$modelA = ModelA::query()
          ->alias('q')
          ->columns(['q.*','concat(q.id,r.id)) 
          ->join('ModelB', 'q.id = r.model_a_id', 'r', 'LEFT');

How can I create an alias q ?

+4
source share
1 answer

The model queryreturns \Phalcon\Mvc\Model\Criteria. There is no way to install alias. You can get what you are trying with modelManageras -

    $modelA = $this->modelsManager->createBuilder()
        ->addFrom('ModelA', 'q')
        ->join('ModelB', 'a.id = r.model_a_id', 'r')
        ->columns(['q.*','concat(q.id,r.id))
        ->getQuery()
        ->execute();
+4
source

All Articles