[DDC-1933] Problem with parameters when clone Doctrine\ORM\QueryBuilder Created: 18/Jul/12  Updated: 23/Jul/12  Resolved: 23/Jul/12

Status: Closed
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.3, Git Master
Fix Version/s: Git Master
Security Level: All

Type: Bug Priority: Major
Reporter: Gandzy Ghennady Assignee: Marco Pivetta
Resolution: Fixed Votes: 1
Labels: None


 Description   

Hi, here problem with cloning \Doctrine\ORM\QueryBuilder

Example
$queryBuilder = new QueryBuilder($em);

$queryBuilder->setParameter('parameter1', 'value1');

$copy = clone $queryBuilder;
$copy->setParameter('parameter2', 'value2');


count($queryBuilder->getParameters()) // equals 2
//expects 1


Solution:

QueryBuilder
public function __clone
{
   ......

   $this->parameters = clone $this->parameters;
}


 Comments   
Comment by Marco Pivetta [ 18/Jul/12 ]

Is `$copy = clone $queryBuilder();` a typo?

Comment by Gandzy Ghennady [ 18/Jul/12 ]

Sorry, this is a typo, was meant: $copy = clone $queryBuilder;

Comment by Marco Pivetta [ 20/Jul/12 ]

This is being handled at DDC-1936 (https://github.com/doctrine/doctrine2/pull/404)

Comment by Gandzy Ghennady [ 20/Jul/12 ]

Hi. Thanks for the quick response.

I looked at the changes, and have a question: whether you need to reset the parameters when cloning? Thus broken backward compatibility with versions <2.3.

Comment by Marco Pivetta [ 20/Jul/12 ]

Actually, I just implemented your expected behaviour (see tests), which is compatible with what the `AbstractQuery` does. It can also be done the other way around, waiting for feedback by Benjamin Eberlei

Comment by Marco Pivetta [ 20/Jul/12 ]

Ah, nevermind. You're right. Will change my code

Generated at Sun Apr 20 00:43:16 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.