1
0
Fork 0
mirror of synced 2025-04-01 12:26:11 +03:00

Added getRootEntities to QueryBuilder.

This commit is contained in:
Guilherme Blanco 2011-06-09 15:42:40 -03:00
parent 93521217a6
commit 1f6b49d236
2 changed files with 44 additions and 2 deletions

View file

@ -240,7 +240,7 @@ class QueryBuilder
}
/**
* Gets the root alias of the query. This is the first entity alias involved
* Gets the root aliases of the query. This is the entity aliases involved
* in the construction of the query.
*
* <code>
@ -251,7 +251,7 @@ class QueryBuilder
* $qb->getRootAliases(); // array('u')
* </code>
*
* @return string $rootAlias
* @return array $rootAliases
*/
public function getRootAliases()
{
@ -272,6 +272,39 @@ class QueryBuilder
return $aliases;
}
/**
* Gets the root entities of the query. This is the entity aliases involved
* in the construction of the query.
*
* <code>
* $qb = $em->createQueryBuilder()
* ->select('u')
* ->from('User', 'u');
*
* $qb->getRootEntities(); // array('User')
* </code>
*
* @return array $rootEntities
*/
public function getRootEntities()
{
$entities = 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);
}
$entities[] = $fromClause->getFrom();
}
return $entities;
}
/**
* Sets a query parameter for the query being constructed.
*

View file

@ -652,6 +652,15 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
$this->assertEquals(array('u'), $qb->getRootAliases());
}
public function testGetRootEntities()
{
$qb = $this->_em->createQueryBuilder()
->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u');
$this->assertEquals(array('Doctrine\Tests\Models\CMS\CmsUser'), $qb->getRootEntities());
}
public function testGetSeveralRootAliases()
{
$qb = $this->_em->createQueryBuilder()