Doctrine 1
  1. Doctrine 1
  2. DC-595

Array hydration fails when sorting DESC

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2.1
    • Fix Version/s: None
    • Component/s: Query
    • Labels:
      None
    • Environment:
      Windows, Ubuntu, PostgreSQL,

      Description

      Wrong array hydration results.

      Running toArray() on non hydrated collection
      produces different results than using array hydrator.

      Case1.
      Sorting ASC (works)

      $reputationHydrated = Doctrine_Query::create()
      ->from('User_Model_UserReputation ur')
      ->leftJoin('ur.User u')
      ->leftJoin('ur.Thread t')
      ->leftJoin('t.ForumEntry fe')
      ->where('u.id = ?', 1)
      ->orderBy('ur.event ASC)
      ->execute(null, Doctrine_Core::HYDRATE_ARRAY);

      $reputation = Doctrine_Query::create()
      ->from('User_Model_UserReputation ur')
      ->leftJoin('ur.User u')
      ->leftJoin('ur.Thread t')
      ->leftJoin('t.ForumEntry fe')
      ->where('u.id = ?', 1)
      ->orderBy('ur.event ASC)
      ->execute();

      $reputationToArray = $reputation->toArray();

      die($reputationToArray === $reputationHydrated); // true, as expected

      Case 2.
      Sorting DESC (does not work)

      $reputationHydrated = Doctrine_Query::create()
      ->from('User_Model_UserReputation ur')
      ->leftJoin('ur.User u')
      ->leftJoin('ur.Thread t')
      ->leftJoin('t.ForumEntry fe')
      ->where('u.id = ?', 1)
      ->orderBy('ur.event DESC)
      ->execute(null, Doctrine_Core::HYDRATE_ARRAY);

      $reputation = Doctrine_Query::create()
      ->from('User_Model_UserReputation ur')
      ->leftJoin('ur.User u')
      ->leftJoin('ur.Thread t')
      ->leftJoin('t.ForumEntry fe')
      ->where('u.id = ?', 1)
      ->orderBy('ur.event DESC)
      ->execute();

      $reputationToArray = $reputation->toArray();

      die($reputationToArray === $reputationHydrated); // false, should be true

      Other hydrators do hydrate as expected.

      Seems that something is wrong in Doctrine_Hydrator_Graph.

        Activity

        Hide
        admirau added a comment -

        Changed one condition in Graph.php, and it works.
        Here is a patch:

        — Doctrine/Hydrator/Graph.php
        +++ Doctrine/Hydrator/Graph-new.php
        @@ -212,7 +212,7 @@
        $indexExists = isset($identifierMap[$path][$id[$parent]][$id[$dqlAlias]]);
        $index = $indexExists ? $identifierMap[$path][$id[$parent]][$id[$dqlAlias]] : false;
        $indexIsValid = $index !== false ? isset($prev[$parent][$relationAlias][$index]) : false;

        • if ( $indexExists || ! $indexIsValid) {
          \ No newline at end of file
          + if ( ! $indexExists || ! $indexIsValid) {
          \ No newline at end of file
          $element = $this->getElement($data, $componentName);
          $event->set('data', $element);
          $listeners[$componentName]->postHydrate($event);

        Plase check if this does not breaks something else.
        Tests are passing.

        Show
        admirau added a comment - Changed one condition in Graph.php, and it works. Here is a patch: — Doctrine/Hydrator/Graph.php +++ Doctrine/Hydrator/Graph-new.php @@ -212,7 +212,7 @@ $indexExists = isset($identifierMap [$path] [$id [$parent] ][$id [$dqlAlias] ]); $index = $indexExists ? $identifierMap [$path] [$id [$parent] ][$id [$dqlAlias] ] : false; $indexIsValid = $index !== false ? isset($prev [$parent] [$relationAlias] [$index] ) : false; if ( $indexExists || ! $indexIsValid) { \ No newline at end of file + if ( ! $indexExists || ! $indexIsValid) { \ No newline at end of file $element = $this->getElement($data, $componentName); $event->set('data', $element); $listeners [$componentName] ->postHydrate($event); Plase check if this does not breaks something else. Tests are passing.

          People

          • Assignee:
            Guilherme Blanco
            Reporter:
            admirau
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: