Commit 2e6ed4d0 authored by romanb's avatar romanb

Updated 2 test cases to outline two major issues with the new hydration (at...

Updated 2 test cases to outline two major issues with the new hydration (at least i think that it has to do with the problems):
1) When the result set is in a custom order, components may be doubled (this already occured half a year ago though the symptoms were different (items were assigned to the wrong collection).
2) Accessing related components that are already loaded (but empty) results in lots of extra queries. The only way to get around that is do wrap an isset() check around nearly all places before accessing a relation. This was not the case in earlier revisions though at that time an isset() was sometimes needed, too to prevent extra queries. But now it seems to be necessary everywhere.
parent 682d98f1
......@@ -98,9 +98,15 @@ class Doctrine_CustomResultSetOrder_TestCase extends Doctrine_UnitTestCase {
* 3 | 2 | Third | NULL
*/
public function testQueryWithOrdering() {
$categories = $this->connection->query("FROM CategoryWithPosition.Boards
ORDER BY CategoryWithPosition.position ASC, CategoryWithPosition.Boards.position ASC");
$q = new Doctrine_Query($this->connection);
$categories = $q->select("c.*, b.*")
->from("CategoryWithPosition c")
->leftJoin("c.Boards b")
->orderBy("c.position ASC, b.position ASC")
->execute();
$this->assertEqual(3, $categories->count(), "Some categories were doubled!");
// Check each category
foreach ($categories as $category) {
......@@ -117,7 +123,7 @@ class Doctrine_CustomResultSetOrder_TestCase extends Doctrine_UnitTestCase {
case "Third":
// The third has no boards as expected.
$this->assertEqual(0, $category->Boards->count());
break;
break;
}
}
......
......@@ -59,6 +59,7 @@ class Doctrine_Query_MultiJoin2_TestCase extends Doctrine_UnitTestCase {
}
public function testMultipleJoinFetchingWithDeepJoins() {
$query = new Doctrine_Query($this->connection);
$queryCount = $this->connection->getDbh()->count();
try {
$categories = $query->select('c.*, subCats.*, b.*, le.*, a.*')
->from('QueryTest_Category c')
......@@ -69,6 +70,31 @@ class Doctrine_Query_MultiJoin2_TestCase extends Doctrine_UnitTestCase {
->where('c.parentCategoryId = 0')
->orderBy('c.position ASC, subCats.position ASC, b.position ASC')
->execute();
// Test that accessing a loaded (but empty) relation doesnt trigger an extra query
$this->assertEqual($queryCount + 1, $this->connection->getDbh()->count());
$categories[0]->subCategories;
$this->assertEqual($queryCount + 1, $this->connection->getDbh()->count());
} catch (Doctrine_Exception $e) {
$this->fail();
}
}
public function testMultipleJoinFetchingWithArrayFetching() {
$query = new Doctrine_Query($this->connection);
$queryCount = $this->connection->getDbh()->count();
try {
$categories = $query->select('c.*, subCats.*, b.*, le.*, a.*')
->from('QueryTest_Category c')
->leftJoin('c.subCategories subCats')
->leftJoin('c.boards b')
->leftJoin('b.lastEntry le')
->leftJoin('le.author a')
->where('c.parentCategoryId = 0')
->orderBy('c.position ASC, subCats.position ASC, b.position ASC')
->execute(array(), Doctrine::FETCH_ARRAY);
//echo "<pre>";
//var_dump($categories);
//echo "</pre>";
$this->pass();
} catch (Doctrine_Exception $e) {
$this->fail();
......
......@@ -200,7 +200,7 @@ $test->addTestCase(new Doctrine_SchemaTestCase());
$test->addTestCase(new Doctrine_Query_Condition_TestCase());
$test->addTestCase(new Doctrine_CustomPrimaryKey_TestCase());
$test->addTestCase(new Doctrine_CustomResultSetOrderTestCase());
$test->addTestCase(new Doctrine_CustomResultSetOrder_TestCase());
// Query tests
......
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