1
0
mirror of synced 2025-01-18 06:21:40 +03:00

DDC-1757 test and patched query builder

This commit is contained in:
Aigars Gedroics 2012-04-05 11:30:00 +03:00 committed by Aigars Gedroics
parent d5d47222c1
commit a1ab3e8cf4
2 changed files with 125 additions and 9 deletions

View File

@ -96,6 +96,12 @@ class QueryBuilder
*/
private $_maxResults = null;
/**
* Keeps root entity alias names for join entities
* @var array
*/
private $joinRootAliases = array();
/**
* Initializes a new <tt>QueryBuilder</tt> that uses the given <tt>EntityManager</tt>.
*
@ -234,10 +240,22 @@ class QueryBuilder
* @deprecated Please use $qb->getRootAliases() instead.
* @return string $rootAlias
*/
public function getRootAlias()
public function getRootAlias($rootAlias = null, $alias = null)
{
$aliases = $this->getRootAliases();
return $aliases[0];
if ( ! is_null($rootAlias) && in_array($rootAlias, $this->getRootAliases())) {
// Do nothing
} elseif ( ! is_null($rootAlias) && isset($this->joinRootAliases[$rootAlias])) {
$rootAlias = $this->joinRootAliases[$rootAlias];
} else {
$aliases = $this->getRootAliases();
$rootAlias = $aliases[0];
}
if ( ! is_null($alias)) {
$this->joinRootAliases[$alias] = $rootAlias;
}
return $rootAlias;
}
/**
@ -669,9 +687,7 @@ class QueryBuilder
{
$rootAlias = substr($join, 0, strpos($join, '.'));
if ( ! in_array($rootAlias, $this->getRootAliases())) {
$rootAlias = $this->getRootAlias();
}
$rootAlias = $this->getRootAlias($rootAlias, $alias);
$join = new Expr\Join(
Expr\Join::INNER_JOIN, $join, $alias, $conditionType, $condition, $indexBy
@ -705,9 +721,7 @@ class QueryBuilder
{
$rootAlias = substr($join, 0, strpos($join, '.'));
if ( ! in_array($rootAlias, $this->getRootAliases())) {
$rootAlias = $this->getRootAlias();
}
$rootAlias = $this->getRootAlias($rootAlias, $alias);
$join = new Expr\Join(
Expr\Join::LEFT_JOIN, $join, $alias, $conditionType, $condition, $indexBy

View File

@ -0,0 +1,102 @@
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\ORM\UnitOfWork;
require_once __DIR__ . '/../../../TestInit.php';
class DDC1757Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp()
{
parent::setUp();
try {
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1757A'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1757B'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1757C'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1757D'),
));
} catch(\Exception $ignored) {}
}
public function testFailingCase()
{
$qb = $this->_em->createQueryBuilder();
/* @var $qb \Doctrine\ORM\QueryBuilder */
$qb->select('_a')
->from(__NAMESPACE__ . '\DDC1757A', '_a')
->from(__NAMESPACE__ . '\DDC1757B', '_b')
->join('_b.c', '_c')
->join('_c.d', '_d');
$q = $qb->getQuery();
$dql = $q->getDQL();
$q->getResult();
}
}
/**
* @Entity
*/
class DDC1757A
{
/**
* @Column(type="integer")
* @Id
* @GeneratedValue(strategy="AUTO")
*/
private $id;
}
/**
* @Entity
*/
class DDC1757B
{
/**
* @Column(type="integer")
* @Id
* @GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @OneToOne(targetEntity="DDC1757C")
*/
private $c;
}
/**
* @Entity
*/
class DDC1757C
{
/**
* @Column(type="integer")
* @Id
* @GeneratedValue(strategy="AUTO")
*/
public $id;
/**
* @OneToOne(targetEntity="DDC1757D")
*/
private $d;
}
/**
* @Entity
*/
class DDC1757D
{
/**
* @Column(type="integer")
* @Id
* @GeneratedValue(strategy="AUTO")
*/
public $id;
}