Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2953

ArrayHydrator: Not all items hydrated while orderBy

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Critical 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

          Hide
          Marco Pivetta added a comment -
          Show
          Marco Pivetta added a comment - I've started work on this at https://github.com/doctrine/doctrine2/pull/933
          Hide
          Mariusz Jaskółka added a comment - - edited

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

          Show
          Mariusz Jaskółka added a comment - - edited This is how I temporary solved the issue, maybe it can help (attachment).
          Hide
          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
          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 Jaskółka added a comment -

          Version 2.4.2 oryginal file and bugfix

          Show
          Mariusz Jaskółka added a comment - Version 2.4.2 oryginal file and bugfix
          Hide
          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 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
          Marco Pivetta added a comment -

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

          Show
          Marco Pivetta added a comment - Mariusz Jaskółka thanks! I'm trying it right now
          Hide
          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 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
          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
          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 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 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
          Marco Pivetta added a comment -

          Mariusz Jaskółka fixed, thanks!

          Show
          Marco Pivetta added a comment - Mariusz Jaskółka fixed, thanks!
          Hide
          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
          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
          Guilherme Blanco added a comment -

          ... and introducing BC breaks.

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

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

          Show
          Doctrine Bot added a comment - A related Github Pull-Request [GH-933] was closed: https://github.com/doctrine/doctrine2/pull/933

            People

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

              Dates

              • Created:
                Updated: