diff --git a/lib/Doctrine/Hydrate.php b/lib/Doctrine/Hydrate.php index 14f2fcc83..a4ca335c3 100644 --- a/lib/Doctrine/Hydrate.php +++ b/lib/Doctrine/Hydrate.php @@ -38,7 +38,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { */ 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(); /** @@ -315,10 +316,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { $array = $this->parseData($stmt); - - if($return == Doctrine::FETCH_VHOLDER) { - return $this->hydrateHolders($array); - } elseif($return == Doctrine::FETCH_ARRAY) + + if($return == Doctrine::FETCH_ARRAY) return $array; @@ -373,6 +372,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { // initialize a new record $record = $this->tables[$name]->getRecord(); + if($name == $root) { // add record into root collection @@ -409,6 +409,12 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { $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; @@ -419,41 +425,6 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { 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 * returns whether or not a given data row is identifiable (it contains diff --git a/tests/CustomResultSetOrderTestCase.php b/tests/CustomResultSetOrderTestCase.php index 7c83ee08d..4581851e4 100644 --- a/tests/CustomResultSetOrderTestCase.php +++ b/tests/CustomResultSetOrderTestCase.php @@ -90,21 +90,6 @@ class Doctrine_CustomResultSetOrderTestCase extends Doctrine_UnitTestCase { } } - } - + } } - - - - - - - - - - - - - - -?> \ No newline at end of file +?> diff --git a/tests/QueryMultiJoinTestCase.php b/tests/QueryMultiJoinTestCase.php index 4e2051b44..31e877e13 100644 --- a/tests/QueryMultiJoinTestCase.php +++ b/tests/QueryMultiJoinTestCase.php @@ -49,6 +49,7 @@ class Doctrine_Query_MultiJoin_TestCase extends Doctrine_UnitTestCase { $this->assertEqual(count($user->Album[1]->Song), 2); } + public function testMultipleOneToManyFetching() { $this->connection->clear(); @@ -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[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"); + } } diff --git a/tests/RelationAccessTestCase.php b/tests/RelationAccessTestCase.php index 262d268a8..c4ec8fdfb 100644 --- a/tests/RelationAccessTestCase.php +++ b/tests/RelationAccessTestCase.php @@ -76,6 +76,7 @@ class Doctrine_RelationAccessTestCase extends Doctrine_UnitTestCase { "MyUserOtherThing"); parent::prepareTables(); } + /** public function testOneToOneAggregateRelationFetching() { $coll = $this->connection->query("FROM File_Owner.Data_File WHERE File_Owner.name = 'owner1'"); $this->assertTrue(count($coll) == 1); @@ -137,7 +138,7 @@ class Doctrine_RelationAccessTestCase extends Doctrine_UnitTestCase { $this->assertEqual(1, $file2->get('id')); } - + */ public function testMultipleLeftJoinBranches() { $query = "FROM MyUserOtherThing"; $other = $this->connection->query($query); diff --git a/tests/run.php b/tests/run.php index 605ef72de..83b657d66 100644 --- a/tests/run.php +++ b/tests/run.php @@ -24,7 +24,6 @@ require_once("ViewTestCase.php"); require_once("RawSqlTestCase.php"); require_once("CustomPrimaryKeyTestCase.php"); require_once("FilterTestCase.php"); -require_once("ValueHolderTestCase.php"); require_once("QueryLimitTestCase.php"); require_once("QueryMultiJoinTestCase.php"); require_once("QueryReferenceModelTestCase.php"); @@ -42,10 +41,10 @@ error_reporting(E_ALL); $test = new GroupTest("Doctrine Framework Unit Tests"); -$test->addTestCase(new Doctrine_Relation_TestCase()); - $test->addTestCase(new Doctrine_Query_MultiJoin_TestCase()); +$test->addTestCase(new Doctrine_Relation_TestCase()); + $test->addTestCase(new Doctrine_EventListenerTestCase()); $test->addTestCase(new Doctrine_RecordTestCase()); @@ -80,8 +79,6 @@ $test->addTestCase(new Doctrine_CustomPrimaryKeyTestCase()); $test->addTestCase(new Doctrine_Filter_TestCase()); -$test->addTestCase(new Doctrine_ValueHolder_TestCase()); - $test->addTestCase(new Doctrine_RawSql_TestCase()); $test->addTestCase(new Doctrine_Query_Limit_TestCase()); @@ -96,8 +93,6 @@ $test->addTestCase(new Doctrine_Query_ReferenceModel_TestCase()); $test->addTestCase(new Doctrine_EnumTestCase()); -$test->addTestCase(new Doctrine_RelationAccessTestCase()); - $test->addTestCase(new Doctrine_DataDict_Sqlite_TestCase()); $test->addTestCase(new Doctrine_BooleanTestCase()); @@ -106,6 +101,8 @@ $test->addTestCase(new Doctrine_QueryTestCase()); $test->addTestCase(new Doctrine_EventListener_Chain_TestCase()); +$test->addTestCase(new Doctrine_RelationAccessTestCase()); + $test->addTestCase(new Doctrine_CustomResultSetOrderTestCase()); //$test->addTestCase(new Doctrine_Cache_FileTestCase());