Uploaded image for project: 'Doctrine 2 - ORM'
  1. Doctrine 2 - ORM
  2. DDC-2953

ArrayHydrator: Not all items hydrated while orderBy

    Details

    • Type: Bug
    • Status: Open
    • Priority: Critical
    • Resolution: Unresolved
    • Affects Version/s: 2.3.4, 2.4.1
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
    • Environment:
      Linux and Windows, PHP5

      Description

      I will explain the problem using example and pseudo-code:

      I have query like that:
      SELECT (...) FROM order LEFT JOIN person LEFT JOIN identifier (...) order by (...)

      The rows returned by query are following (the order is very important):
      order_id|person_id|identifier_id|
      12 |21 |33 |
      12 |21 |34 |
      11 |21 |35 |
      11 |21 |33 |
      11 |21 |34 |
      12 |21 |35 |

      After hydration the result is like:
      result[0][person][identifier][0][id]=33
      result[0][person][identifier][0][id]=34
      result[1][person][identifier][0][id]=35
      result[1][person][identifier][0][id]=34

      But it should be:
      result[0][person][identifier][0][id]=33
      result[0][person][identifier][0][id]=34
      result[0][person][identifier][0][id]=35
      result[1][person][identifier][0][id]=35
      result[1][person][identifier][0][id]=34
      result[1][person][identifier][0][id]=33

      The reason is that ArrayHydrator::_identifierMap contains only object id and parents object id. In may example there is difference in parents parent (grandparent) id.

      1. Array_hydrator_4.2_bugfix.php
        12 kB
        Mariusz Jaskółka
      2. Array_Hydrator_4.2.php
        11 kB
        Mariusz Jaskółka
      3. ArrayHydrator.php
        12 kB
        Mariusz Jaskółka

        Issue Links

          Activity

          mariusz.jaskolka Mariusz Jaskółka created issue -
          ocramius Marco Pivetta made changes -
          Field Original Value New Value
          Assignee Benjamin Eberlei [ beberlei ] Marco Pivetta [ ocramius ]
          Hide
          ocramius Marco Pivetta added a comment -
          Show
          ocramius Marco Pivetta added a comment - I've started work on this at https://github.com/doctrine/doctrine2/pull/933
          ocramius Marco Pivetta made changes -
          Priority Major [ 3 ] Critical [ 2 ]
          Hide
          mariusz.jaskolka Mariusz Jaskółka added a comment - - edited

          This is how I temporary solved the issue, maybe it can help (attachment).

          Show
          mariusz.jaskolka Mariusz Jaskółka added a comment - - edited This is how I temporary solved the issue, maybe it can help (attachment).
          mariusz.jaskolka Mariusz Jaskółka made changes -
          Attachment ArrayHydrator.php [ 11715 ]
          Hide
          ocramius Marco Pivetta added a comment -

          Mariusz Jaskółka can you provide a diff with current master? This seems to be based off 2.3 or previous versions...

          Show
          ocramius Marco Pivetta added a comment - Mariusz Jaskółka can you provide a diff with current master? This seems to be based off 2.3 or previous versions...
          Hide
          mariusz.jaskolka Mariusz Jaskółka added a comment -

          Version 2.4.2 oryginal file and bugfix

          Show
          mariusz.jaskolka Mariusz Jaskółka added a comment - Version 2.4.2 oryginal file and bugfix
          mariusz.jaskolka Mariusz Jaskółka made changes -
          Attachment Array_Hydrator_4.2.php [ 11716 ]
          Attachment Array_hydrator_4.2_bugfix.php [ 11717 ]
          Hide
          mariusz.jaskolka Mariusz Jaskółka added a comment -

          Oh sorry it is version 2.4.1 (composer downloaded that version for me).
          I hope it will be ok.

          Show
          mariusz.jaskolka Mariusz Jaskółka added a comment - Oh sorry it is version 2.4.1 (composer downloaded that version for me). I hope it will be ok.
          Hide
          ocramius Marco Pivetta added a comment -

          Mariusz Jaskółka thanks! I'm trying it right now

          Show
          ocramius Marco Pivetta added a comment - Mariusz Jaskółka thanks! I'm trying it right now
          Hide
          mariusz.jaskolka Mariusz Jaskółka added a comment -

          I added one dimention to $this->_identifierMap to be sure that all object's children's keys will be mapped separately.

          Show
          mariusz.jaskolka Mariusz Jaskółka added a comment - I added one dimention to $this->_identifierMap to be sure that all object's children's keys will be mapped separately.
          Hide
          ocramius Marco Pivetta added a comment - - edited

          Mariusz Jaskółka, I've applied your hotfix at https://github.com/doctrine/doctrine2/commit/c05921032ff6947daca2d7275031e5cde4700634 and the tests seem to pass on my system and on travis. You may want to check it out and see if it works for your use case.

          Show
          ocramius Marco Pivetta added a comment - - edited Mariusz Jaskółka , I've applied your hotfix at https://github.com/doctrine/doctrine2/commit/c05921032ff6947daca2d7275031e5cde4700634 and the tests seem to pass on my system and on travis. You may want to check it out and see if it works for your use case.
          Hide
          mariusz.jaskolka Mariusz Jaskółka added a comment -

          It works for my use case correctly. You apparently forgot to remove/comment line 82 which is not necessary now.

          Show
          mariusz.jaskolka Mariusz Jaskółka added a comment - It works for my use case correctly. You apparently forgot to remove/comment line 82 which is not necessary now.
          Hide
          ocramius Marco Pivetta added a comment -

          Mariusz Jaskółka fixed, thanks!

          Show
          ocramius Marco Pivetta added a comment - Mariusz Jaskółka fixed, thanks!
          ocramius Marco Pivetta made changes -
          Assignee Marco Pivetta [ ocramius ] Guilherme Blanco [ guilhermeblanco ]
          Hide
          ocramius Marco Pivetta added a comment -

          I don't think we'll have a fix for this issue for 2.5, as it will probably require a complete rewrite of the array hydrator

          Show
          ocramius Marco Pivetta added a comment - I don't think we'll have a fix for this issue for 2.5, as it will probably require a complete rewrite of the array hydrator
          Hide
          guilhermeblanco Guilherme Blanco added a comment -

          ... and introducing BC breaks.

          Show
          guilhermeblanco Guilherme Blanco added a comment - ... and introducing BC breaks.
          Hide
          doctrinebot Doctrine Bot added a comment -

          A related Github Pull-Request [GH-933] was closed:
          https://github.com/doctrine/doctrine2/pull/933

          Show
          doctrinebot Doctrine Bot added a comment - A related Github Pull-Request [GH-933] was closed: https://github.com/doctrine/doctrine2/pull/933
          ocramius Marco Pivetta made changes -
          Link This issue depends on DDC-2955 [ DDC-2955 ]

          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={expand=changesets[0:20].revisions[0:29],reviews, query=DDC-2953}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

            People

            • Assignee:
              guilhermeblanco Guilherme Blanco
              Reporter:
              mariusz.jaskolka Mariusz Jaskółka
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: