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

        Gandzy Ghennady created issue -
        Hide
        Marco Pivetta added a comment -

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

        Show
        Marco Pivetta added a comment - Is `$copy = clone $queryBuilder();` a typo?
        Marco Pivetta made changes -
        Field Original Value New Value
        Status Open [ 1 ] Awaiting Feedback [ 10000 ]
        Marco Pivetta made changes -
        Status Awaiting Feedback [ 10000 ] In Progress [ 3 ]
        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;
        Gandzy Ghennady made changes -
        Description Hi, here problem with cloning \Doctrine\ORM\QueryBuilder

        {code:title=Example}
        $queryBuilder = new QueryBuilder($em);

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

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


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


        {code}


        Solution:
        {code:title=QueryBuilder}
        public function __clone
        {
           ......

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

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

        {code:title=Example}
        $queryBuilder = new QueryBuilder($em);

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

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


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


        {code}


        Solution:
        {code:title=QueryBuilder}
        public function __clone
        {
           ......

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

        Marco Pivetta made changes -
        Assignee Benjamin Eberlei [ beberlei ] Marco Pivetta [ ocramius ]
        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 -

        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 -

        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
        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
        Marco Pivetta made changes -
        Status In Progress [ 3 ] Closed [ 6 ]
        Fix Version/s Git Master [ 10100 ]
        Resolution Fixed [ 1 ]

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-1933, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

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

            Dates

            • Created:
              Updated:
              Resolved: