Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if alias exists?

How I could check if the alias is already defined?

There is no method for check this.

Thats not working because I got only the ROOT alias and no join aliases.

/** @var $query \Doctrine\ORM\QueryBuilder */
$query->getRootAliases()

The parts is another invalid option for me...

$query->getDQLPart()

Returns only the parts like "select, from, etc.".

And thats the error I would "ignore".

[Semantical Error] line 0, col 254 near '_user LEFT': Error: '_user' is already defined.

How could I check if the alias exists?

like image 663
PatrickB Avatar asked Mar 20 '14 15:03

PatrickB


1 Answers

You could use PHP native in_array function to check if the value exists in the array or not.

in_array($alias, $qb->getAllAliases())
like image 64
Léo Benoist Avatar answered Sep 17 '22 09:09

Léo Benoist