1
0
mirror of synced 2024-12-13 14:56:01 +03:00

Fixed fatal bug in Doctrine_Hydrate resulting in wrong mappings when result set contains rows in 'wrong' order.

This commit is contained in:
zYne 2006-10-01 14:35:38 +00:00
parent bc76914310
commit ab99a5fcc3
5 changed files with 26 additions and 65 deletions

View File

@ -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

View File

@ -90,21 +90,6 @@ class Doctrine_CustomResultSetOrderTestCase extends Doctrine_UnitTestCase {
}
}
}
}
}
?>
?>

View File

@ -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");
}
}

View File

@ -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);

View File

@ -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());