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

DDC-867 - Deep clone of the QueryBuilder nested expression objects

This commit is contained in:
Benjamin Eberlei 2010-11-15 21:32:38 +01:00
parent e62fb0b48e
commit 85a579febc
2 changed files with 40 additions and 0 deletions

View File

@ -932,4 +932,24 @@ class QueryBuilder
{
return $this->getDQL();
}
/**
* Deep clone of all expression objects in the DQL parts.
*
* @return void
*/
public function __clone()
{
foreach ($this->_dqlParts AS $part => $elements) {
if (is_array($this->_dqlParts[$part])) {
foreach ($this->_dqlParts[$part] AS $idx => $element) {
if (is_object($element)) {
$this->_dqlParts[$part][$idx] = clone $element;
}
}
} else if (\is_object($elements)) {
$this->_dqlParts[$part] = clone $elements;
}
}
}
}

View File

@ -569,4 +569,24 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
$this->assertNull($qb->getDQLPart('where'));
$this->assertEquals(0, count($qb->getDQLPart('orderBy')));
}
/**
* @group DDC-867
*/
public function testDeepClone()
{
$qb = $this->_em->createQueryBuilder()
->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->andWhere('u.username = ?1')
->andWhere('u.status = ?2');
$expr = $qb->getDQLPart('where');
$this->assertEquals(2, $expr->count(), "Modifying the second query should affect the first one.");
$qb2 = clone $qb;
$qb2->andWhere('u.name = ?3');
$this->assertEquals(2, $expr->count(), "Modifying the second query should affect the first one.");
}
}