DDC-867 - Deep clone of the QueryBuilder nested expression objects
This commit is contained in:
parent
e62fb0b48e
commit
85a579febc
@ -932,4 +932,24 @@ class QueryBuilder
|
|||||||
{
|
{
|
||||||
return $this->getDQL();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -569,4 +569,24 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
$this->assertNull($qb->getDQLPart('where'));
|
$this->assertNull($qb->getDQLPart('where'));
|
||||||
$this->assertEquals(0, count($qb->getDQLPart('orderBy')));
|
$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.");
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user