1
0
Fork 0
mirror of synced 2025-04-03 13:23:37 +03:00

Changed QueryBuilder to allow retrieval of all defined root alises.

This commit is contained in:
Guilherme Blanco 2011-05-14 00:40:23 -03:00
parent e538128645
commit 08f2af489e

View file

@ -227,15 +227,28 @@ class QueryBuilder
* ->select('u') * ->select('u')
* ->from('User', 'u'); * ->from('User', 'u');
* *
* echo $qb->getRootAlias(); // u * $qb->getRootAliases(); // array('u')
* </code> * </code>
* *
* @return string $rootAlias * @return string $rootAlias
* @todo Rename/Refactor: getRootAliases(), there can be multiple roots!
*/ */
public function getRootAlias() public function getRootAliases()
{ {
return $this->_dqlParts['from'][0]->getAlias(); $aliases = array();
foreach ($this->_dqlParts['from'] as &$fromClause) {
if (is_string($fromClause)) {
$spacePos = strrpos($fromClause, ' ');
$from = substr($fromClause, 0, $spacePos);
$alias = substr($fromClause, $spacePos + 1);
$fromClause = new Query\Expr\From($from, $alias);
}
$aliases[] = $fromClause->getAlias();
}
return $aliases;
} }
/** /**