[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


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

$queryBuilder = new QueryBuilder($em);

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

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

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


public function __clone

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

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 Tue Nov 24 23:21:36 EST 2015 using JIRA 6.4.10#64025-sha1:5b8b74079161cd76a20ab66dda52747ee6701bd6.