Reintroduce QueryBuilder::getRootAlias() for backwards compatibility reasons, mark as @deprecated
This commit is contained in:
parent
5e938b3147
commit
85d40847ac
2 changed files with 50 additions and 0 deletions
|
@ -217,6 +217,27 @@ class QueryBuilder
|
||||||
->setFirstResult($this->_firstResult)
|
->setFirstResult($this->_firstResult)
|
||||||
->setMaxResults($this->_maxResults);
|
->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
|
* Gets the root alias of the query. This is the first entity alias involved
|
||||||
|
|
|
@ -633,4 +633,33 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||||
|
|
||||||
$this->assertEquals(2, $expr->count(), "Modifying the second query should affect the first one.");
|
$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());
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue