Commit ab99a5fc authored by zYne's avatar zYne

Fixed fatal bug in Doctrine_Hydrate resulting in wrong mappings when result...

Fixed fatal bug in Doctrine_Hydrate resulting in wrong mappings when result set contains rows in 'wrong' order. 
parent bc769143
...@@ -38,7 +38,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { ...@@ -38,7 +38,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
*/ */
protected $tables = array(); protected $tables = array();
/** /**
* @var array $collections an array containing all collections this parser has created/will create * @var array $collections an array containing all collections
* this hydrater has created/will create
*/ */
protected $collections = array(); protected $collections = array();
/** /**
...@@ -316,9 +317,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { ...@@ -316,9 +317,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
$array = $this->parseData($stmt); $array = $this->parseData($stmt);
if($return == Doctrine::FETCH_VHOLDER) { if($return == Doctrine::FETCH_ARRAY)
return $this->hydrateHolders($array);
} elseif($return == Doctrine::FETCH_ARRAY)
return $array; return $array;
...@@ -373,6 +372,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { ...@@ -373,6 +372,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
// initialize a new record // initialize a new record
$record = $this->tables[$name]->getRecord(); $record = $this->tables[$name]->getRecord();
if($name == $root) { if($name == $root) {
// add record into root collection // add record into root collection
...@@ -409,6 +409,12 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { ...@@ -409,6 +409,12 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
$last->addReference($record, $fk); $last->addReference($record, $fk);
} }
} }
// following statement is needed to ensure that mappings are being done properly when
// the result set doesn't contain the rows in 'right order' the
if($prev[$name] !== $record)
$prev[$name] = $record;
} }
$previd[$name] = $row; $previd[$name] = $row;
...@@ -419,41 +425,6 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { ...@@ -419,41 +425,6 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
endswitch; endswitch;
} }
/**
* hydrateHolders
*
* @param array $array
*/
public function hydrateHolders(array $array) {
$keys = array_keys($this->tables);
$root = $keys[0];
$coll = new Doctrine_ValueHolder($this->tables[$root]);
foreach($keys as $key) {
$prev[$key] = array();
}
foreach($array as $data) {
foreach($data as $alias => $row) {
if(isset($prev[$alias]) && $row !== $prev[$alias]) {
$holder = new Doctrine_ValueHolder($this->tables[$alias]);
$holder->data = $row;
if($alias === $root) {
$coll->data[] = $holder;
} else {
$pointer = $this->joins[$alias];
$component = $this->tables[$alias]->getComponentName();
$last[$pointer]->data[$component][] = $holder;
}
$last[$alias] = $holder;
}
$prev[$alias] = $row;
}
}
return $coll;
}
/** /**
* isIdentifiable * isIdentifiable
* returns whether or not a given data row is identifiable (it contains * returns whether or not a given data row is identifiable (it contains
......
...@@ -91,20 +91,5 @@ class Doctrine_CustomResultSetOrderTestCase extends Doctrine_UnitTestCase { ...@@ -91,20 +91,5 @@ class Doctrine_CustomResultSetOrderTestCase extends Doctrine_UnitTestCase {
} }
} }
} }
?> ?>
...@@ -49,6 +49,7 @@ class Doctrine_Query_MultiJoin_TestCase extends Doctrine_UnitTestCase { ...@@ -49,6 +49,7 @@ class Doctrine_Query_MultiJoin_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual(count($user->Album[1]->Song), 2); $this->assertEqual(count($user->Album[1]->Song), 2);
} }
public function testMultipleOneToManyFetching() { public function testMultipleOneToManyFetching() {
$this->connection->clear(); $this->connection->clear();
...@@ -142,4 +143,10 @@ class Doctrine_Query_MultiJoin_TestCase extends Doctrine_UnitTestCase { ...@@ -142,4 +143,10 @@ class Doctrine_Query_MultiJoin_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($users[1]->Book[1]->Author[0]->name, 'Someone'); $this->assertEqual($users[1]->Book[1]->Author[0]->name, 'Someone');
$this->assertEqual($users[1]->Book[0]->Author[1]->name, 'Voltaire'); $this->assertEqual($users[1]->Book[0]->Author[1]->name, 'Voltaire');
} }
public function testMultipleOneToManyFetchingWithOrderBy() {
$query = new Doctrine_Query();
$users = $query->query("FROM User.Album.Song WHERE User.id IN (4,5) ORDER BY User.Album.Song.title DESC");
}
} }
...@@ -76,6 +76,7 @@ class Doctrine_RelationAccessTestCase extends Doctrine_UnitTestCase { ...@@ -76,6 +76,7 @@ class Doctrine_RelationAccessTestCase extends Doctrine_UnitTestCase {
"MyUserOtherThing"); "MyUserOtherThing");
parent::prepareTables(); parent::prepareTables();
} }
/**
public function testOneToOneAggregateRelationFetching() { public function testOneToOneAggregateRelationFetching() {
$coll = $this->connection->query("FROM File_Owner.Data_File WHERE File_Owner.name = 'owner1'"); $coll = $this->connection->query("FROM File_Owner.Data_File WHERE File_Owner.name = 'owner1'");
$this->assertTrue(count($coll) == 1); $this->assertTrue(count($coll) == 1);
...@@ -137,7 +138,7 @@ class Doctrine_RelationAccessTestCase extends Doctrine_UnitTestCase { ...@@ -137,7 +138,7 @@ class Doctrine_RelationAccessTestCase extends Doctrine_UnitTestCase {
$this->assertEqual(1, $file2->get('id')); $this->assertEqual(1, $file2->get('id'));
} }
*/
public function testMultipleLeftJoinBranches() { public function testMultipleLeftJoinBranches() {
$query = "FROM MyUserOtherThing"; $query = "FROM MyUserOtherThing";
$other = $this->connection->query($query); $other = $this->connection->query($query);
......
...@@ -24,7 +24,6 @@ require_once("ViewTestCase.php"); ...@@ -24,7 +24,6 @@ require_once("ViewTestCase.php");
require_once("RawSqlTestCase.php"); require_once("RawSqlTestCase.php");
require_once("CustomPrimaryKeyTestCase.php"); require_once("CustomPrimaryKeyTestCase.php");
require_once("FilterTestCase.php"); require_once("FilterTestCase.php");
require_once("ValueHolderTestCase.php");
require_once("QueryLimitTestCase.php"); require_once("QueryLimitTestCase.php");
require_once("QueryMultiJoinTestCase.php"); require_once("QueryMultiJoinTestCase.php");
require_once("QueryReferenceModelTestCase.php"); require_once("QueryReferenceModelTestCase.php");
...@@ -42,10 +41,10 @@ error_reporting(E_ALL); ...@@ -42,10 +41,10 @@ error_reporting(E_ALL);
$test = new GroupTest("Doctrine Framework Unit Tests"); $test = new GroupTest("Doctrine Framework Unit Tests");
$test->addTestCase(new Doctrine_Relation_TestCase());
$test->addTestCase(new Doctrine_Query_MultiJoin_TestCase()); $test->addTestCase(new Doctrine_Query_MultiJoin_TestCase());
$test->addTestCase(new Doctrine_Relation_TestCase());
$test->addTestCase(new Doctrine_EventListenerTestCase()); $test->addTestCase(new Doctrine_EventListenerTestCase());
$test->addTestCase(new Doctrine_RecordTestCase()); $test->addTestCase(new Doctrine_RecordTestCase());
...@@ -80,8 +79,6 @@ $test->addTestCase(new Doctrine_CustomPrimaryKeyTestCase()); ...@@ -80,8 +79,6 @@ $test->addTestCase(new Doctrine_CustomPrimaryKeyTestCase());
$test->addTestCase(new Doctrine_Filter_TestCase()); $test->addTestCase(new Doctrine_Filter_TestCase());
$test->addTestCase(new Doctrine_ValueHolder_TestCase());
$test->addTestCase(new Doctrine_RawSql_TestCase()); $test->addTestCase(new Doctrine_RawSql_TestCase());
$test->addTestCase(new Doctrine_Query_Limit_TestCase()); $test->addTestCase(new Doctrine_Query_Limit_TestCase());
...@@ -96,8 +93,6 @@ $test->addTestCase(new Doctrine_Query_ReferenceModel_TestCase()); ...@@ -96,8 +93,6 @@ $test->addTestCase(new Doctrine_Query_ReferenceModel_TestCase());
$test->addTestCase(new Doctrine_EnumTestCase()); $test->addTestCase(new Doctrine_EnumTestCase());
$test->addTestCase(new Doctrine_RelationAccessTestCase());
$test->addTestCase(new Doctrine_DataDict_Sqlite_TestCase()); $test->addTestCase(new Doctrine_DataDict_Sqlite_TestCase());
$test->addTestCase(new Doctrine_BooleanTestCase()); $test->addTestCase(new Doctrine_BooleanTestCase());
...@@ -106,6 +101,8 @@ $test->addTestCase(new Doctrine_QueryTestCase()); ...@@ -106,6 +101,8 @@ $test->addTestCase(new Doctrine_QueryTestCase());
$test->addTestCase(new Doctrine_EventListener_Chain_TestCase()); $test->addTestCase(new Doctrine_EventListener_Chain_TestCase());
$test->addTestCase(new Doctrine_RelationAccessTestCase());
$test->addTestCase(new Doctrine_CustomResultSetOrderTestCase()); $test->addTestCase(new Doctrine_CustomResultSetOrderTestCase());
//$test->addTestCase(new Doctrine_Cache_FileTestCase()); //$test->addTestCase(new Doctrine_Cache_FileTestCase());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment