Added getRootEntities to QueryBuilder.
This commit is contained in:
parent
93521217a6
commit
1f6b49d236
2 changed files with 44 additions and 2 deletions
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Add table
Reference in a new issue