1
0
mirror of synced 2025-01-18 22:41:43 +03:00

Reintroduce QueryBuilder::getRootAlias() for backwards compatibility reasons, mark as @deprecated

This commit is contained in:
Benjamin Eberlei 2011-05-15 22:11:10 +02:00
parent 5e938b3147
commit 85d40847ac
2 changed files with 50 additions and 0 deletions

View File

@ -217,6 +217,27 @@ class QueryBuilder
->setFirstResult($this->_firstResult)
->setMaxResults($this->_maxResults);
}
/**
* Gets the FIRST root alias of the query. This is the first entity alias involved
* in the construction of the query.
*
* <code>
* $qb = $em->createQueryBuilder()
* ->select('u')
* ->from('User', 'u');
*
* echo $qb->getRootAlias(); // u
* </code>
*
* @deprecated Please use $qb->getRootAliases() instead.
* @return string $rootAlias
*/
public function getRootAlias()
{
$aliases = $this->getRootAliases();
return $aliases[0];
}
/**
* Gets the root alias of the query. This is the first entity alias involved

View File

@ -633,4 +633,33 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
$this->assertEquals(2, $expr->count(), "Modifying the second query should affect the first one.");
}
public function testGetRootAlias()
{
$qb = $this->_em->createQueryBuilder()
->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u');
$this->assertEquals('u', $qb->getRootAlias());
}
public function testGetRootAliases()
{
$qb = $this->_em->createQueryBuilder()
->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u');
$this->assertEquals(array('u'), $qb->getRootAliases());
}
public function testGetSeveralRootAliases()
{
$qb = $this->_em->createQueryBuilder()
->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u2');
$this->assertEquals(array('u', 'u2'), $qb->getRootAliases());
$this->assertEquals('u', $qb->getRootAlias());
}
}