We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

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.

\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.