diff --git a/lib/Doctrine/Hydrator.php b/lib/Doctrine/Hydrator.php
index f424f51d0..d3b53362e 100644
--- a/lib/Doctrine/Hydrator.php
+++ b/lib/Doctrine/Hydrator.php
@@ -197,7 +197,7 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
$oneToOne = false;
// append element
if (isset($nonemptyComponents[$dqlAlias])) {
- $driver->initRelated($prev[$parent], $relationAlias);
+ $driver->initRelatedCollection($prev[$parent], $relationAlias);
if ( ! isset($identifierMap[$path][$id[$parent]][$id[$dqlAlias]])) {
$element = $driver->getElement($data, $componentName);
@@ -225,6 +225,8 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
}
// register collection for later snapshots
//$driver->registerCollection($prev[$parent][$relationAlias]);
+ } else if ( ! isset($prev[$parent][$relationAlias])) {
+ $prev[$parent][$relationAlias] = $driver->getNullPointer();
}
} else {
// 1-1 relation
@@ -236,8 +238,10 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
$prev[$parent][$relationAlias] = $element;
}
}
- $coll =& $prev[$parent][$relationAlias];
- $this->_setLastElement($prev, $coll, $index, $dqlAlias, $oneToOne);
+ if ($prev[$parent][$relationAlias] !== null) {
+ $coll =& $prev[$parent][$relationAlias];
+ $this->_setLastElement($prev, $coll, $index, $dqlAlias, $oneToOne);
+ }
}
}
diff --git a/lib/Doctrine/Hydrator/ArrayDriver.php b/lib/Doctrine/Hydrator/ArrayDriver.php
index 8bdcc81dc..e293e1901 100644
--- a/lib/Doctrine/Hydrator/ArrayDriver.php
+++ b/lib/Doctrine/Hydrator/ArrayDriver.php
@@ -66,7 +66,7 @@ class Doctrine_Hydrator_ArrayDriver
/**
*
*/
- public function initRelated(array &$data, $name)
+ public function initRelatedCollection(array &$data, $name)
{
if ( ! isset($data[$name])) {
$data[$name] = array();
diff --git a/lib/Doctrine/Hydrator/RecordDriver.php b/lib/Doctrine/Hydrator/RecordDriver.php
index fe6094cf2..106f5b364 100644
--- a/lib/Doctrine/Hydrator/RecordDriver.php
+++ b/lib/Doctrine/Hydrator/RecordDriver.php
@@ -68,7 +68,7 @@ class Doctrine_Hydrator_RecordDriver
}
}
- public function initRelated(Doctrine_Record $record, $name)
+ public function initRelatedCollection(Doctrine_Record $record, $name)
{
if ( ! isset($this->_initializedRelations[$record->getOid()][$name])) {
$relation = $record->getClassMetadata()->getRelation($name);
diff --git a/lib/Doctrine/HydratorNew.php b/lib/Doctrine/HydratorNew.php
index b730ab38d..925a29af8 100644
--- a/lib/Doctrine/HydratorNew.php
+++ b/lib/Doctrine/HydratorNew.php
@@ -20,8 +20,27 @@
*/
/**
- * The hydrator has the tedious task to construct object or array graphs out of
- * a database result set.
+ * The hydrator has the tedious to process result sets returned by the database
+ * and turn them into useable structures.
+ *
+ * Runtime complexity: The following gives the overall number of iterations
+ * required to process a result set.
+ *
+ * numRowsInResult * numColumnsInResult + numRowsInResult * numClassesInQuery
+ *
+ * This comes down to:
+ *
+ * (numRowsInResult * (numColumnsInResult + numClassesInQuery))
+ *
+ * Note that this is only a crude definition of the complexity as it also heavily
+ * depends on the complexity of all the single operations that are performed in
+ * each iteration.
+ *
+ * As can be seen, the number of columns in the result has the most impact on
+ * the overall performance (apart from the row counr, of course), since numClassesInQuery
+ * is usually pretty low.
+ * That's why the performance of the gatherRowData() method which is responsible
+ * for the "numRowsInResult * numColumnsInResult" part is crucial to fast hydraton.
*
* @package Doctrine
* @subpackage Hydrator
@@ -153,9 +172,9 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
// do we need to index by a custom field?
if ($field = $this->_getCustomIndexField($rootAlias)) {
if (isset($result[$field])) {
- throw new Doctrine_Hydrator_Exception("Couldn't hydrate. Found non-unique key mapping.");
+ throw Doctrine_Hydrator_Exception::nonUniqueKeyMapping();
} else if ( ! isset($element[$field])) {
- throw new Doctrine_Hydrator_Exception("Couldn't hydrate. Found a non-existent key.");
+ throw Doctrine_Hydrator_Exception::nonExistantFieldUsedAsIndex($field);
}
if ($this->_isResultMixed) {
$result[] = array($element[$field] => $element);
@@ -169,7 +188,6 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
$result[] = $element;
}
}
-
$identifierMap[$rootAlias][$id[$rootAlias]] = $driver->getLastKey($result);
} else {
$index = $identifierMap[$rootAlias][$id[$rootAlias]];
@@ -185,7 +203,7 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
unset($rowData['scalars']);
}
- // $prev[$rootAlias] now points to the last element in $result.
+ // $resultPointers[$rootAlias] now points to the last element in $result.
// now hydrate the rest of the data found in the current row, that belongs to other
// (related) components.
foreach ($rowData as $dqlAlias => $data) {
@@ -204,21 +222,23 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
$path = $parent . '.' . $dqlAlias;
- $key = key(reset($resultPointers));
- if ($this->_isResultMixed && $parent == $rootAlias && isset($resultPointers[$parent][$key])) {
+ // pick the right element that will get the associated element attached
+ if ($this->_isResultMixed && $parent == $rootAlias) {
+ $key = key(reset($resultPointers));
+ // TODO: Exception if $key === null ?
$baseElement =& $resultPointers[$parent][$key];
} else if (isset($resultPointers[$parent])) {
$baseElement =& $resultPointers[$parent];
} else {
continue;
}
-
+
// check the type of the relation (many or single-valued)
if ( ! $relation->isOneToOne()) {
// x-many relation
$oneToOne = false;
if (isset($nonemptyComponents[$dqlAlias])) {
- $driver->initRelated($baseElement, $relationAlias);
+ $driver->initRelatedCollection($baseElement, $relationAlias);
if ( ! isset($identifierMap[$path][$id[$parent]][$id[$dqlAlias]])) {
$element = $driver->getElement($data, $componentName);
@@ -244,18 +264,22 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
} else {
$index = $identifierMap[$path][$id[$parent]][$id[$dqlAlias]];
}
+ } else if ( ! isset($baseElement[$relationAlias])) {
+ $baseElement[$relationAlias] = $driver->getNullPointer();
}
} else {
// x-1 relation
- $oneToOne = true;
+ $oneToOne = true;
if ( ! isset($nonemptyComponents[$dqlAlias])) {
$baseElement[$relationAlias] = $driver->getNullPointer();
} else if ( ! isset($baseElement[$relationAlias])) {
$baseElement[$relationAlias] = $driver->getElement($data, $componentName);
}
}
- $coll =& $baseElement[$relationAlias];
- $this->_setLastElement($resultPointers, $coll, $index, $dqlAlias, $oneToOne);
+ if ($baseElement[$relationAlias] !== null) {
+ $coll =& $baseElement[$relationAlias];
+ $this->_setLastElement($resultPointers, $coll, $index, $dqlAlias, $oneToOne);
+ }
}
// append scalar values
diff --git a/lib/Doctrine/Mapper.php b/lib/Doctrine/Mapper.php
index bc3237413..3781c0508 100644
--- a/lib/Doctrine/Mapper.php
+++ b/lib/Doctrine/Mapper.php
@@ -615,7 +615,9 @@ class Doctrine_Mapper
public function saveAssociations(Doctrine_Record $record)
{
foreach ($record->getReferences() as $relationName => $relatedObject) {
-
+ if ($relatedObject === Doctrine_Null::$INSTANCE) {
+ continue;
+ }
$rel = $record->getTable()->getRelation($relationName);
if ($rel instanceof Doctrine_Relation_Association) {
diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php
index 5e8244ed4..71706860e 100644
--- a/lib/Doctrine/Record.php
+++ b/lib/Doctrine/Record.php
@@ -928,6 +928,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$rel = $this->_class->getRelation($fieldName);
$this->_references[$fieldName] = $rel->fetchRelatedFor($this);
}
+ if ($this->_references[$fieldName] === Doctrine_Null::$INSTANCE) {
+ return null;
+ }
return $this->_references[$fieldName];
} catch (Doctrine_Relation_Exception $e) {
//echo $e->getTraceAsString();
@@ -1038,14 +1041,19 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
*/
private function _coreSetRelated($name, $value)
{
+ if ($value === Doctrine_Null::$INSTANCE) {
+ $this->_references[$name] = $value;
+ return;
+ }
+
$rel = $this->_class->getRelation($name);
// one-to-many or one-to-one relation
if ($rel instanceof Doctrine_Relation_ForeignKey ||
- $rel instanceof Doctrine_Relation_LocalKey) {
+ $rel instanceof Doctrine_Relation_LocalKey) {
if ( ! $rel->isOneToOne()) {
// one-to-many relation found
- if ( ! ($value instanceof Doctrine_Collection)) {
+ if ( ! $value instanceof Doctrine_Collection) {
throw new Doctrine_Record_Exception("Couldn't call Doctrine::set(), second"
. " argument should be an instance of Doctrine_Collection when"
. " setting one-to-many references.");
@@ -1067,7 +1075,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
. " or Doctrine_Null when setting one-to-one references.");
}
if ($rel instanceof Doctrine_Relation_LocalKey) {
- $idFieldNames = (array)$value->getTable()->getIdentifier();
+ $idFieldNames = $value->getTable()->getIdentifier();
if ( ! empty($foreignFieldName) && $foreignFieldName != $idFieldNames[0]) {
$this->set($localFieldName, $value->rawGet($foreignFieldName), false);
} else {
@@ -1097,6 +1105,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
public function contains($fieldName)
{
if (isset($this->_data[$fieldName])) {
+ if ($this->_data[$fieldName] === Doctrine_Null::$INSTANCE) {
+ return false;
+ }
return true;
}
if (isset($this->_id[$fieldName])) {
diff --git a/tests/Orm/Hydration/BasicHydrationTest.php b/tests/Orm/Hydration/BasicHydrationTest.php
index 990e71cf3..208c15607 100644
--- a/tests/Orm/Hydration/BasicHydrationTest.php
+++ b/tests/Orm/Hydration/BasicHydrationTest.php
@@ -9,22 +9,21 @@ class Orm_Hydration_BasicHydrationTest extends Doctrine_OrmTestCase
parent::setUp();
}
- /** The data of the hydration mode dataProvider */
- protected static $hydrationModeProviderData = array(
- array('hydrationMode' => Doctrine::HYDRATE_RECORD),
- array('hydrationMode' => Doctrine::HYDRATE_ARRAY)
- );
/** Getter for the hydration mode dataProvider */
public static function hydrationModeProvider()
{
- return self::$hydrationModeProviderData;
+ return array(
+ array('hydrationMode' => Doctrine::HYDRATE_RECORD),
+ array('hydrationMode' => Doctrine::HYDRATE_ARRAY)
+ );
}
/**
* Select u.id, u.name from CmsUser u
*
+ * @dataProvider hydrationModeProvider
*/
- public function testBasicHydration()
+ public function testNewHydrationSimpleEntityQuery($hydrationMode)
{
// Faked query components
$queryComponents = array(
@@ -44,12 +43,10 @@ class Orm_Hydration_BasicHydrationTest extends Doctrine_OrmTestCase
// Faked result set
$resultSet = array(
- //row1
array(
'u__id' => '1',
'u__name' => 'romanb'
),
- //row2
array(
'u__id' => '2',
'u__name' => 'jwage'
@@ -58,30 +55,24 @@ class Orm_Hydration_BasicHydrationTest extends Doctrine_OrmTestCase
$stmt = new Doctrine_HydratorMockStatement($resultSet);
- $hydrator = new Doctrine_Hydrator();
+ $hydrator = new Doctrine_HydratorNew();
$hydrator->setQueryComponents($queryComponents);
- $arrayResult = $hydrator->hydrateResultSet($stmt, $tableAliasMap, Doctrine::HYDRATE_ARRAY);
-
- $this->assertTrue(is_array($arrayResult));
- $this->assertEquals(2, count($arrayResult));
- $this->assertEquals(1, $arrayResult[0]['id']);
- $this->assertEquals('romanb', $arrayResult[0]['name']);
- $this->assertEquals(2, $arrayResult[1]['id']);
- $this->assertEquals('jwage', $arrayResult[1]['name']);
-
- $stmt->setResultSet($resultSet);
- $objectResult = $hydrator->hydrateResultSet($stmt, $tableAliasMap, Doctrine::HYDRATE_RECORD);
-
- $this->assertTrue($objectResult instanceof Doctrine_Collection);
- $this->assertEquals(2, count($objectResult));
- $this->assertTrue($objectResult[0] instanceof Doctrine_Record);
- $this->assertEquals(1, $objectResult[0]->id);
- $this->assertEquals('romanb', $objectResult[0]->name);
- $this->assertTrue($objectResult[1] instanceof Doctrine_Record);
- $this->assertEquals(2, $objectResult[1]->id);
- $this->assertEquals('jwage', $objectResult[1]->name);
+ $result = $hydrator->hydrateResultSet($stmt, $tableAliasMap, $hydrationMode);
+ $this->assertEquals(2, count($result));
+ $this->assertEquals(1, $result[0]['id']);
+ $this->assertEquals('romanb', $result[0]['name']);
+ $this->assertEquals(2, $result[1]['id']);
+ $this->assertEquals('jwage', $result[1]['name']);
+
+ if ($hydrationMode == Doctrine::HYDRATE_RECORD) {
+ $this->assertTrue($result instanceof Doctrine_Collection);
+ $this->assertTrue($result[0] instanceof Doctrine_Record);
+ $this->assertTrue($result[1] instanceof Doctrine_Record);
+ } else {
+ $this->assertTrue(is_array($result));
+ }
}
/**
@@ -188,7 +179,7 @@ class Orm_Hydration_BasicHydrationTest extends Doctrine_OrmTestCase
*
* @dataProvider hydrationModeProvider
*/
- public function testNewHydrationBasicsMixedQueryNormalJoin($hydrationMode)
+ public function testNewHydrationMixedQueryNormalJoin($hydrationMode)
{
// Faked query components
$queryComponents = array(
@@ -354,11 +345,10 @@ class Orm_Hydration_BasicHydrationTest extends Doctrine_OrmTestCase
$this->assertTrue($result[0]['1']['phonenumbers'] instanceof Doctrine_Collection);
$this->assertEquals(2, count($result[0]['1']['phonenumbers']));
}
-
}
-/**
+ /**
* select u.id, u.status, p.phonenumber, upper(u.name) nameUpper, a.id, a.topic
* from User u
* join u.phonenumbers p
@@ -509,8 +499,304 @@ class Orm_Hydration_BasicHydrationTest extends Doctrine_OrmTestCase
}
}
+ /**
+ * select u.id, u.status, p.phonenumber, upper(u.name) nameUpper, a.id, a.topic,
+ * c.id, c.topic
+ * from User u
+ * join u.phonenumbers p
+ * join u.articles a
+ * left join a.comments c
+ * =
+ * select u.id, u.status, p.phonenumber, upper(u.name) as u__0, a.id, a.topic,
+ * c.id, c.topic
+ * from USERS u
+ * inner join PHONENUMBERS p ON u.id = p.user_id
+ * inner join ARTICLES a ON u.id = a.user_id
+ * left outer join COMMENTS c ON a.id = c.article_id
+ *
+ * @dataProvider hydrationModeProvider
+ */
+ public function testNewHydrationMixedQueryMultipleDeepMixedFetchJoin($hydrationMode)
+ {
+ // Faked query components
+ $queryComponents = array(
+ 'u' => array(
+ 'table' => $this->sharedFixture['connection']->getClassMetadata('CmsUser'),
+ 'mapper' => $this->sharedFixture['connection']->getMapper('CmsUser'),
+ 'parent' => null,
+ 'relation' => null,
+ 'map' => null,
+ 'agg' => array('0' => 'nameUpper')
+ ),
+ 'p' => array(
+ 'table' => $this->sharedFixture['connection']->getClassMetadata('CmsPhonenumber'),
+ 'mapper' => $this->sharedFixture['connection']->getMapper('CmsPhonenumber'),
+ 'parent' => 'u',
+ 'relation' => $this->sharedFixture['connection']->getClassMetadata('CmsUser')->getRelation('phonenumbers'),
+ 'map' => null
+ ),
+ 'a' => array(
+ 'table' => $this->sharedFixture['connection']->getClassMetadata('CmsArticle'),
+ 'mapper' => $this->sharedFixture['connection']->getMapper('CmsArticle'),
+ 'parent' => 'u',
+ 'relation' => $this->sharedFixture['connection']->getClassMetadata('CmsUser')->getRelation('articles'),
+ 'map' => null
+ ),
+ 'c' => array(
+ 'table' => $this->sharedFixture['connection']->getClassMetadata('CmsComment'),
+ 'mapper' => $this->sharedFixture['connection']->getMapper('CmsComment'),
+ 'parent' => 'a',
+ 'relation' => $this->sharedFixture['connection']->getClassMetadata('CmsArticle')->getRelation('comments'),
+ 'map' => null
+ ),
+ );
+
+ // Faked table alias map
+ $tableAliasMap = array(
+ 'u' => 'u',
+ 'p' => 'p',
+ 'a' => 'a',
+ 'c' => 'c'
+ );
+
+ // Faked result set
+ $resultSet = array(
+ //row1
+ array(
+ 'u__id' => '1',
+ 'u__status' => 'developer',
+ 'u__0' => 'ROMANB',
+ 'p__phonenumber' => '42',
+ 'a__id' => '1',
+ 'a__topic' => 'Getting things done!',
+ 'c__id' => '1',
+ 'c__topic' => 'First!'
+ ),
+ array(
+ 'u__id' => '1',
+ 'u__status' => 'developer',
+ 'u__0' => 'ROMANB',
+ 'p__phonenumber' => '43',
+ 'a__id' => '1',
+ 'a__topic' => 'Getting things done!',
+ 'c__id' => '1',
+ 'c__topic' => 'First!'
+ ),
+ array(
+ 'u__id' => '1',
+ 'u__status' => 'developer',
+ 'u__0' => 'ROMANB',
+ 'p__phonenumber' => '42',
+ 'a__id' => '2',
+ 'a__topic' => 'ZendCon',
+ 'c__id' => null,
+ 'c__topic' => null
+ ),
+ array(
+ 'u__id' => '1',
+ 'u__status' => 'developer',
+ 'u__0' => 'ROMANB',
+ 'p__phonenumber' => '43',
+ 'a__id' => '2',
+ 'a__topic' => 'ZendCon',
+ 'c__id' => null,
+ 'c__topic' => null
+ ),
+ array(
+ 'u__id' => '2',
+ 'u__status' => 'developer',
+ 'u__0' => 'JWAGE',
+ 'p__phonenumber' => '91',
+ 'a__id' => '3',
+ 'a__topic' => 'LINQ',
+ 'c__id' => null,
+ 'c__topic' => null
+ ),
+ array(
+ 'u__id' => '2',
+ 'u__status' => 'developer',
+ 'u__0' => 'JWAGE',
+ 'p__phonenumber' => '91',
+ 'a__id' => '4',
+ 'a__topic' => 'PHP6',
+ 'c__id' => null,
+ 'c__topic' => null
+ ),
+ );
+
+ $stmt = new Doctrine_HydratorMockStatement($resultSet);
+ $hydrator = new Doctrine_HydratorNew();
+ $hydrator->setQueryComponents($queryComponents);
+
+ $hydrator->setResultMixed(true);
+
+ $result = $hydrator->hydrateResultSet($stmt, $tableAliasMap, $hydrationMode);
+ if ($hydrationMode == Doctrine::HYDRATE_ARRAY) {
+ //var_dump($result);
+ }
+
+ $this->assertEquals(2, count($result));
+ $this->assertTrue(is_array($result));
+ $this->assertTrue(is_array($result[0]));
+ $this->assertTrue(is_array($result[1]));
+
+ // first user => 2 phonenumbers, 2 articles, 1 comment on first article
+ $this->assertEquals(2, count($result[0][0]['phonenumbers']));
+ $this->assertEquals(2, count($result[0][0]['articles']));
+ $this->assertEquals(1, count($result[0][0]['articles'][0]['comments']));
+ $this->assertEquals('ROMANB', $result[0]['nameUpper']);
+ // second user => 1 phonenumber, 2 articles, no comments
+ $this->assertEquals(1, count($result[1][0]['phonenumbers']));
+ $this->assertEquals(2, count($result[1][0]['articles']));
+ $this->assertEquals('JWAGE', $result[1]['nameUpper']);
+
+ $this->assertEquals(42, $result[0][0]['phonenumbers'][0]['phonenumber']);
+ $this->assertEquals(43, $result[0][0]['phonenumbers'][1]['phonenumber']);
+ $this->assertEquals(91, $result[1][0]['phonenumbers'][0]['phonenumber']);
+
+ $this->assertEquals('Getting things done!', $result[0][0]['articles'][0]['topic']);
+ $this->assertEquals('ZendCon', $result[0][0]['articles'][1]['topic']);
+ $this->assertEquals('LINQ', $result[1][0]['articles'][0]['topic']);
+ $this->assertEquals('PHP6', $result[1][0]['articles'][1]['topic']);
+
+ $this->assertEquals('First!', $result[0][0]['articles'][0]['comments'][0]['topic']);
+
+ $this->assertTrue(isset($result[0][0]['articles'][0]['comments']));
+ $this->assertFalse(isset($result[0][0]['articles'][1]['comments']));
+ $this->assertFalse(isset($result[1][0]['articles'][0]['comments']));
+ $this->assertFalse(isset($result[1][0]['articles'][1]['comments']));
+
+ if ($hydrationMode == Doctrine::HYDRATE_RECORD) {
+ $this->assertTrue($result[0][0] instanceof Doctrine_Record);
+ $this->assertTrue($result[1][0] instanceof Doctrine_Record);
+ // phonenumbers
+ $this->assertTrue($result[0][0]['phonenumbers'] instanceof Doctrine_Collection);
+ $this->assertTrue($result[0][0]['phonenumbers'][0] instanceof Doctrine_Record);
+ $this->assertTrue($result[0][0]['phonenumbers'][1] instanceof Doctrine_Record);
+ $this->assertTrue($result[1][0]['phonenumbers'] instanceof Doctrine_Collection);
+ $this->assertTrue($result[1][0]['phonenumbers'][0] instanceof Doctrine_Record);
+ // articles
+ $this->assertTrue($result[0][0]['articles'] instanceof Doctrine_Collection);
+ $this->assertTrue($result[0][0]['articles'][0] instanceof Doctrine_Record);
+ $this->assertTrue($result[0][0]['articles'][1] instanceof Doctrine_Record);
+ $this->assertTrue($result[1][0]['articles'][0] instanceof Doctrine_Record);
+ $this->assertTrue($result[1][0]['articles'][1] instanceof Doctrine_Record);
+ // article comments
+ $this->assertTrue($result[0][0]['articles'][0]['comments'] instanceof Doctrine_Collection);
+ $this->assertTrue($result[0][0]['articles'][0]['comments'][0] instanceof Doctrine_Record);
+ }
+ }
-
-
+ /**
+ * Tests that the hydrator does not rely on a particular order of the rows
+ * in the result set.
+ *
+ * DQL:
+ * select c.id, c.position, c.name, b.id, b.position
+ * from ForumCategory c inner join c.boards b
+ * order by c.position asc, b.position asc
+ *
+ * Checks whether the boards are correctly assigned to the categories.
+ *
+ * The 'evil' result set that confuses the object population is displayed below.
+ *
+ * c.id | c.position | c.name | boardPos | b.id | b.category_id (just for clarity)
+ * 1 | 0 | First | 0 | 1 | 1
+ * 2 | 0 | Second | 0 | 2 | 2 <--
+ * 1 | 0 | First | 1 | 3 | 1
+ * 1 | 0 | First | 2 | 4 | 1
+ *
+ * @dataProvider hydrationModeProvider
+ */
+ public function testNewHydrationEntityQueryCustomResultSetOrder($hydrationMode)
+ {
+ // Faked query components
+ $queryComponents = array(
+ 'c' => array(
+ 'table' => $this->sharedFixture['connection']->getClassMetadata('ForumCategory'),
+ 'mapper' => $this->sharedFixture['connection']->getMapper('ForumCategory'),
+ 'parent' => null,
+ 'relation' => null,
+ 'map' => null
+ ),
+ 'b' => array(
+ 'table' => $this->sharedFixture['connection']->getClassMetadata('ForumBoard'),
+ 'mapper' => $this->sharedFixture['connection']->getMapper('ForumBoard'),
+ 'parent' => 'c',
+ 'relation' => $this->sharedFixture['connection']->getClassMetadata('ForumCategory')->getRelation('boards'),
+ 'map' => null
+ ),
+ );
+
+ // Faked table alias map
+ $tableAliasMap = array(
+ 'c' => 'c',
+ 'b' => 'b'
+ );
+
+ // Faked result set
+ $resultSet = array(
+ array(
+ 'c__id' => '1',
+ 'c__position' => '0',
+ 'c__name' => 'First',
+ 'b__id' => '1',
+ 'b__position' => '0',
+ 'b__category_id' => '1'
+ ),
+ array(
+ 'c__id' => '2',
+ 'c__position' => '0',
+ 'c__name' => 'Second',
+ 'b__id' => '2',
+ 'b__position' => '0',
+ 'b__category_id' => '2'
+ ),
+ array(
+ 'c__id' => '1',
+ 'c__position' => '0',
+ 'c__name' => 'First',
+ 'b__id' => '3',
+ 'b__position' => '1',
+ 'b__category_id' => '1'
+ ),
+ array(
+ 'c__id' => '1',
+ 'c__position' => '0',
+ 'c__name' => 'First',
+ 'b__id' => '4',
+ 'b__position' => '2',
+ 'b__category_id' => '1'
+ )
+ );
+
+ $stmt = new Doctrine_HydratorMockStatement($resultSet);
+ $hydrator = new Doctrine_HydratorNew();
+ $hydrator->setQueryComponents($queryComponents);
+
+ //$hydrator->setResultMixed(true);
+
+ $result = $hydrator->hydrateResultSet($stmt, $tableAliasMap, $hydrationMode);
+ if ($hydrationMode == Doctrine::HYDRATE_ARRAY) {
+ //var_dump($result);
+ }
+
+ $this->assertEquals(2, count($result));
+ $this->assertTrue(isset($result[0]['boards']));
+ $this->assertEquals(3, count($result[0]['boards']));
+ $this->assertTrue(isset($result[1]['boards']));
+ $this->assertEquals(1, count($result[1]['boards']));
+
+ if ($hydrationMode == Doctrine::HYDRATE_ARRAY) {
+ $this->assertTrue(is_array($result));
+ $this->assertTrue(is_array($result[0]));
+ $this->assertTrue(is_array($result[1]));
+ } else {
+ $this->assertTrue($result instanceof Doctrine_Collection);
+ $this->assertTrue($result[0] instanceof Doctrine_Record);
+ $this->assertTrue($result[1] instanceof Doctrine_Record);
+ }
+
+ }
}
\ No newline at end of file
diff --git a/tests/models/cms/CmsArticle.php b/tests/models/cms/CmsArticle.php
index 9de10e6d9..eec67826b 100644
--- a/tests/models/cms/CmsArticle.php
+++ b/tests/models/cms/CmsArticle.php
@@ -7,5 +7,7 @@ class CmsArticle extends Doctrine_Record
$class->mapColumn('topic', 'string', 255);
$class->mapColumn('text', 'string');
$class->mapColumn('user_id', 'integer', 4);
+ $class->hasMany('CmsComment as comments', array(
+ 'local' => 'id', 'foreign' => 'article_id'));
}
}
diff --git a/tests/models/cms/CmsComment.php b/tests/models/cms/CmsComment.php
new file mode 100644
index 000000000..ddca225d6
--- /dev/null
+++ b/tests/models/cms/CmsComment.php
@@ -0,0 +1,11 @@
+mapColumn('id', 'integer', 4, array('primary' => true, 'autoincrement' => true));
+ $class->mapColumn('topic', 'string', 255);
+ $class->mapColumn('text', 'string');
+ $class->mapColumn('article_id', 'integer', 4);
+ }
+}
diff --git a/tests/models/forum/ForumBoard.php b/tests/models/forum/ForumBoard.php
new file mode 100644
index 000000000..ccf5aca57
--- /dev/null
+++ b/tests/models/forum/ForumBoard.php
@@ -0,0 +1,9 @@
+mapColumn('position', 'integer');
+ $class->mapColumn('category_id', 'integer');
+ $class->hasOne('ForumCategory as category',
+ array('local' => 'category_id', 'foreign' => 'id'));
+ }
+}
diff --git a/tests/models/forum/ForumCategory.php b/tests/models/forum/ForumCategory.php
new file mode 100644
index 000000000..890f6160c
--- /dev/null
+++ b/tests/models/forum/ForumCategory.php
@@ -0,0 +1,9 @@
+mapColumn('position', 'integer');
+ $class->mapColumn('name', 'string', 255);
+ $class->hasMany('ForumBoard as boards', array(
+ 'local' => 'id' , 'foreign' => 'category_id'));
+ }
+}
diff --git a/tests_old/AccessTestCase.php b/tests_old/AccessTestCase.php
index e31ea50de..8b8f616cf 100644
--- a/tests_old/AccessTestCase.php
+++ b/tests_old/AccessTestCase.php
@@ -49,10 +49,10 @@ class Doctrine_Access_TestCase extends Doctrine_UnitTestCase
{
$user = new User();
- $this->assertTrue(isset($user->name));
+ $this->assertTrue(!isset($user->name));
$this->assertFalse(isset($user->unknown));
- $this->assertTrue(isset($user['name']));
+ $this->assertTrue(!isset($user['name']));
$this->assertFalse(isset($user['unknown']));
$coll = new Doctrine_Collection('User');
diff --git a/tests_old/CustomResultSetOrderTestCase.php b/tests_old/CustomResultSetOrderTestCase.php
index 8aeecf468..edc113cf6 100644
--- a/tests_old/CustomResultSetOrderTestCase.php
+++ b/tests_old/CustomResultSetOrderTestCase.php
@@ -169,7 +169,7 @@ class Doctrine_CustomResultSetOrder_TestCase extends Doctrine_UnitTestCase {
case 'Third':
// The third has no boards as expected.
//print $category->Boards[0]->position;
- $this->assertEqual(0, $category->Boards->count());
+ $this->assertTrue(!isset($category->Boards));
break;
}
diff --git a/tests_old/Record/SynchronizeTestCase.php b/tests_old/Record/SynchronizeTestCase.php
index c462ef405..b4883afa7 100644
--- a/tests_old/Record/SynchronizeTestCase.php
+++ b/tests_old/Record/SynchronizeTestCase.php
@@ -115,7 +115,7 @@ class Doctrine_Record_Synchronize_TestCase extends Doctrine_UnitTestCase
public function testSynchronizeAfterRemoveRecord()
{
$user = Doctrine_Query::create()->from('User u, u.Email, u.Phonenumber')->fetchOne();
- $this->assertEqual($user->Phonenumber->count(), 0);
+ $this->assertTrue(!isset($user->Phonenumber));
$this->assertTrue(!isset($user->Email));
}
}
diff --git a/tests_old/RecordTestCase.php b/tests_old/RecordTestCase.php
index 666b35070..02ae21afa 100644
--- a/tests_old/RecordTestCase.php
+++ b/tests_old/RecordTestCase.php
@@ -113,9 +113,9 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
$user = new User();
- $this->assertTrue(isset($user->id));
- $this->assertTrue(isset($user['id']));
- $this->assertTrue($user->contains('id'));
+ $this->assertTrue(!isset($user->id));
+ $this->assertTrue(!isset($user['id']));
+ $this->assertTrue(!$user->contains('id'));
}
public function testNotNullConstraint()
diff --git a/tests_old/Relation/OneToOneTestCase.php b/tests_old/Relation/OneToOneTestCase.php
index a29939bc5..9328ba339 100644
--- a/tests_old/Relation/OneToOneTestCase.php
+++ b/tests_old/Relation/OneToOneTestCase.php
@@ -83,7 +83,7 @@ class Doctrine_Relation_OneToOne_TestCase extends Doctrine_UnitTestCase
$this->assertTrue($user->Email instanceOf Email);
$user->Email = Doctrine_Null::$INSTANCE;
$user->save();
- $this->assertTrue($user->Email instanceOf Doctrine_Null);
+ $this->assertTrue($user->Email === null);
}
public function testSavingRelatedObjects()