Skip to content

Loading…

DDC-1933: Problem with parameters when clone Doctrine\ORM\QueryBuilder #2603

Closed
doctrinebot opened this Issue · 7 comments

2 participants

@doctrinebot

Jira issue originally created by user ghennady:

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


Solution:

public function **clone
{
   ......

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

Comment created by @ocramius:

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

@doctrinebot

Comment created by ghennady:

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

@doctrinebot

Comment created by @ocramius:

This is being handled at DDC-1936 (#404)

@doctrinebot

Comment created by ghennady:

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.

@doctrinebot

Comment created by @ocramius:

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 [~beberlei] :)

@doctrinebot

Comment created by @ocramius:

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

@doctrinebot

Issue was closed with resolution "Fixed"

@Ocramius Ocramius was assigned by doctrinebot
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.