Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.2
    • Fix Version/s: 2.4
    • Component/s: DQL
    • Security Level: All
    • Labels:
      None

      Description

      This is basically a duplicate of another issue I stumbled across lately but cannot find here again. It added a __clone() function to the ORM QueryBuilder to allow this use case:
      Create a base query and derive two different queries from it.

      I adopted the code for the DBAL QueryBuilder which is suffering the same issue (e.g. expressions were not cloned but shared between instances). The code is tested at least for my limited use case.

          /**
           * Deep clone of all expression objects in the SQL parts.
           *
           * @return void
           */
          public function __clone()
          {
              foreach ($this->sqlParts as $part => $elements) {
                  if (is_array($this->sqlParts[$part])) {
                      foreach ($this->sqlParts[$part] as $idx => $element) {
                          if (is_object($element)) {
                              $this->sqlParts[$part][$idx] = clone $element;
                          }
                      }
                  } else if (is_object($elements)) {
                      $this->sqlParts[$part] = clone $elements;
                  }
              }
      
              $params = array();
      
              foreach ($this->params as $param) {
                  $params[] = clone $param;
              }
      
              $this->params = $params;
          }
      

        Issue Links

          Activity

          Tim Mundt created issue -
          Benjamin Eberlei made changes -
          Field Original Value New Value
          Description This is basically a duplicate of another issue I stumbled across lately but cannot find here again. It added a __clone() function to the ORM QueryBuilder to allow this use case:
          Create a base query and derive two different queries from it.

          I adopted the code for the DBAL QueryBuilder which is suffering the same issue (e.g. expressions were not cloned but shared between instances). The code is tested at least for my limited use case.


              /**
               * Deep clone of all expression objects in the SQL parts.
               *
               * @return void
               */
              public function __clone()
              {
                  foreach ($this->sqlParts as $part => $elements) {
                      if (is_array($this->sqlParts[$part])) {
                          foreach ($this->sqlParts[$part] as $idx => $element) {
                              if (is_object($element)) {
                                  $this->sqlParts[$part][$idx] = clone $element;
                              }
                          }
                      } else if (is_object($elements)) {
                          $this->sqlParts[$part] = clone $elements;
                      }
                  }

                  $params = array();

                  foreach ($this->params as $param) {
                      $params[] = clone $param;
                  }

                  $this->params = $params;
              }
          This is basically a duplicate of another issue I stumbled across lately but cannot find here again. It added a __clone() function to the ORM QueryBuilder to allow this use case:
          Create a base query and derive two different queries from it.

          I adopted the code for the DBAL QueryBuilder which is suffering the same issue (e.g. expressions were not cloned but shared between instances). The code is tested at least for my limited use case.

          {code}
              /**
               * Deep clone of all expression objects in the SQL parts.
               *
               * @return void
               */
              public function __clone()
              {
                  foreach ($this->sqlParts as $part => $elements) {
                      if (is_array($this->sqlParts[$part])) {
                          foreach ($this->sqlParts[$part] as $idx => $element) {
                              if (is_object($element)) {
                                  $this->sqlParts[$part][$idx] = clone $element;
                              }
                          }
                      } else if (is_object($elements)) {
                          $this->sqlParts[$part] = clone $elements;
                      }
                  }

                  $params = array();

                  foreach ($this->params as $param) {
                      $params[] = clone $param;
                  }

                  $this->params = $params;
              }
          {code}
          Hide
          Tim Mundt added a comment -

          Thanks for adding the code tags. Just updated my doctrine to 2.4-RC1 and did not find this in there. Would be nice to see this in the new version. Any obstacles I could be of help with?

          Show
          Tim Mundt added a comment - Thanks for adding the code tags. Just updated my doctrine to 2.4-RC1 and did not find this in there. Would be nice to see this in the new version. Any obstacles I could be of help with?
          Hide
          Marco Pivetta added a comment -
          Show
          Marco Pivetta added a comment - Tim Mundt , there's an open PR at https://github.com/doctrine/dbal/pull/327
          Benjamin Eberlei made changes -
          Link This issue is duplicated by DBAL-537 [ DBAL-537 ]
          Hide
          Benjamin Eberlei added a comment -

          Fixed in 2.4

          Show
          Benjamin Eberlei added a comment - Fixed in 2.4
          Benjamin Eberlei made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Fix Version/s 2.4 [ 10321 ]
          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-2313, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

            People

            • Assignee:
              Benjamin Eberlei
              Reporter:
              Tim Mundt
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: