Details
-
Type:
Bug
-
Status:
Open
-
Priority:
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.
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;
\ 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.