6

How to set an SQL alias for a Phalcon Model. A method alias() does not exist.

A sample 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 q alias?

Mihai Petcu
  • 368
  • 2
  • 14

1 Answers1

6

Model query returns \Phalcon\Mvc\Model\Criteria. There is not method to set alias. You can get what are you trying with modelManager as-

    $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();
Fazal Rasel
  • 4,446
  • 2
  • 20
  • 31