We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

\Phalcon\Mvc\Model\Query\Builder alias?

For example:

 $builder = $this->modelsManager->createBuilder()
                ->from('\Core\Model\LanguageTranslation')
                ->where("\\Core\\Model\\LanguageTranslation.original LIKE '%{$search}%'")
                ->orWhere("\\Core\\Model\\LanguageTranslation.translated LIKE '%{$search}%'");

Too long... Is there some possibility to add alias for table?



98.9k
Accepted
answer

You can use an alias this way:

 $builder = $this->modelsManager->createBuilder()
                ->from(array('la' => '\Core\Model\LanguageTranslation'))
                ->where("la.original LIKE '%{$search}%'")
                ->orWhere("la.translated LIKE '%{$search}%'");

Oh, thanks you, missed this in documentation in a rush.