How to get doctrine2 table alias?
The QueryBuilder object has two relevant methods:- getRootAliases()- getRootEntities()
Calling getRootAliases on a a QueryBuilder which has the from
clause set will return an array of all aliases; similarly, calling getRootEntities will return an array of the shortened class names of the selected entities.
$qb = $em->createQueryBuilder();$qb->from('BundleName:EntityName', 'entityName');var_dump($qb->getRootAliases()); // returns ['entityName']
I managed to get alias with
$alias = current($builder->getDQLPart('from'))->getAlias();
(where $builder is an instance of Doctrine\ORM\QueryBuilder)