Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1933

Problem with parameters when clone Doctrine\ORM\QueryBuilder

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.3, Git Master
    • Fix Version/s: Git Master
    • Component/s: ORM
    • Security Level: All
    • 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;
      }
      

        Activity

        Hide
        Marco Pivetta added a comment -

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

        Show
        Marco Pivetta added a comment - Ah, nevermind. You're right. Will change my code
        Hide
        Marco Pivetta added a comment -

        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

        Show
        Marco Pivetta added a comment - 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
        Hide
        Gandzy Ghennady added a comment -

        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.

        Show
        Gandzy Ghennady added a comment - 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.
        Hide
        Marco Pivetta added a comment -
        Show
        Marco Pivetta added a comment - This is being handled at DDC-1936 ( https://github.com/doctrine/doctrine2/pull/404 )
        Hide
        Gandzy Ghennady added a comment -

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

        Show
        Gandzy Ghennady added a comment - Sorry, this is a typo, was meant: $copy = clone $queryBuilder;
        Hide
        Marco Pivetta added a comment -

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

        Show
        Marco Pivetta added a comment - Is `$copy = clone $queryBuilder();` a typo?

          People

          • Assignee:
            Marco Pivetta
            Reporter:
            Gandzy Ghennady
          • Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: