From 62860d51919b83d7d696a888b29c555d8f4a0bd2 Mon Sep 17 00:00:00 2001 From: romanb Date: Fri, 11 Jan 2008 13:53:30 +0000 Subject: [PATCH] fixed joincondition tests. --- lib/Doctrine/Hydrator.php | 3 +-- lib/Doctrine/Query.php | 4 ++-- lib/Doctrine/Record.php | 2 +- tests/Query/JoinCondition2TestCase.php | 32 ++++++++++++++++---------- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/lib/Doctrine/Hydrator.php b/lib/Doctrine/Hydrator.php index 90f0027c0..3651ad9ba 100644 --- a/lib/Doctrine/Hydrator.php +++ b/lib/Doctrine/Hydrator.php @@ -61,7 +61,6 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract public function hydrateResultSet($stmt, $tableAliases, $hydrationMode = null) { //$s = microtime(true); - $this->_tableAliases = $tableAliases; if ($hydrationMode == Doctrine::HYDRATE_NONE) { @@ -284,7 +283,7 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract protected function _gatherRowData(&$data, &$cache, &$id, &$nonemptyComponents) { $rowData = array(); - + foreach ($data as $key => $value) { // Parse each column name only once. Cache the results. if ( ! isset($cache[$key])) { diff --git a/lib/Doctrine/Query.php b/lib/Doctrine/Query.php index 1e0931c49..39c6ea92a 100644 --- a/lib/Doctrine/Query.php +++ b/lib/Doctrine/Query.php @@ -481,7 +481,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria public function processPendingFields($componentAlias) { $tableAlias = $this->getTableAlias($componentAlias); - $table = $this->_queryComponents[$componentAlias]['table']; + $table = $this->_queryComponents[$componentAlias]['table']; if ( ! isset($this->_pendingFields[$componentAlias])) { return; @@ -1610,8 +1610,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria $this->_pendingJoinConditions[$componentAlias] = $joinCondition; } } - if ($loadFields) { + if ($loadFields) { $restoreState = false; // load fields if necessary if ($loadFields && empty($this->_dqlParts['select'])) { diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index 4e1463cca..04b9c7546 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -910,7 +910,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count * @return Doctrine_Record */ public function set($fieldName, $value, $load = true) - { + { if (isset($this->_data[$fieldName])) { if ($value instanceof Doctrine_Record) { $type = $this->_table->getTypeOf($fieldName); diff --git a/tests/Query/JoinCondition2TestCase.php b/tests/Query/JoinCondition2TestCase.php index 28eaa56c9..10dbbbf69 100755 --- a/tests/Query/JoinCondition2TestCase.php +++ b/tests/Query/JoinCondition2TestCase.php @@ -54,20 +54,22 @@ class Doctrine_Query_JoinCondition2_TestCase extends Doctrine_UnitTestCase $groups->save(); - $zYne = Doctrine_Query::create()->from('User u')->where('u.id = ?', 4)->fetchOne(); + $zYne = Doctrine_Query::create()->from('User u')->where('u.name = ?', 'zYne')->fetchOne(); $zYne->Group[0] = $groups[0]; $zYne->Group[1] = $groups[1]; $zYne->save(); } - public function testJoinCondifitionsRawLeftJoins() + public function testJoinConditionsRawLeftJoins() { $q = Doctrine_Query::create(); - $q->select('u.id')->from('User u')->leftJoin('u.Group g WITH g.id = 12')->where('u.id = 4'); + $q->select('u.id, g.id')->from('User u')->leftJoin('u.Group g WITH g.name = ?', 'Developers')->where('u.name = ?', 'zYne'); - $this->assertEqual($q->getQuery(), 'SELECT e.id AS e__id FROM entity e LEFT JOIN groupuser g ON e.id = g.user_id LEFT JOIN entity e2 ON e2.id = g.group_id AND e2.id = 12 WHERE e.id = 4 AND (e.type = 0 AND (e2.type = 1 OR e2.type IS NULL))'); + $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id, e2.id AS e2__id FROM entity e LEFT JOIN groupuser g" + . " ON e.id = g.user_id LEFT JOIN entity e2 ON e2.id = g.group_id AND e2.name = ?" + . " WHERE e.name = ? AND (e.type = 0 AND (e2.type = 1 OR e2.type IS NULL))"); $rs = $q->execute(); @@ -88,13 +90,15 @@ class Doctrine_Query_JoinCondition2_TestCase extends Doctrine_UnitTestCase } - public function testJoinCondifitionsArgumentsLeftJoins() + public function testJoinConditionsArgumentsLeftJoins() { $q = new Doctrine_Query($this->connection); - $q->select('u.id')->from('User u')->leftJoin('u.Group g WITH g.id = ?', 12)->where('u.id = ?', 4); + $q->select('u.id, g.id')->from('User u')->leftJoin('u.Group g WITH g.id = ?', 12)->where('u.id = ?', 4); - $this->assertEqual($q->getQuery(), 'SELECT e.id AS e__id FROM entity e LEFT JOIN groupuser g ON e.id = g.user_id LEFT JOIN entity e2 ON e2.id = g.group_id AND e2.id = ? WHERE e.id = ? AND (e.type = 0 AND (e2.type = 1 OR e2.type IS NULL))'); + $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id, e2.id AS e2__id FROM entity e" + . " LEFT JOIN groupuser g ON e.id = g.user_id LEFT JOIN entity e2 ON e2.id = g.group_id" + . " AND e2.id = ? WHERE e.id = ? AND (e.type = 0 AND (e2.type = 1 OR e2.type IS NULL))"); $rs = $q->execute(); @@ -115,13 +119,15 @@ class Doctrine_Query_JoinCondition2_TestCase extends Doctrine_UnitTestCase } - public function testJoinCondifitionsRawInnerJoins() + public function testJoinConditionsRawInnerJoins() { $q = new Doctrine_Query($this->connection); - $q->select('u.id')->from('User u')->innerJoin('u.Group g WITH g.id = 12')->where('u.id = 4'); + $q->select('u.id, g.id')->from('User u')->innerJoin('u.Group g WITH g.id = 12')->where('u.id = 4'); - $this->assertEqual($q->getQuery(), 'SELECT e.id AS e__id FROM entity e INNER JOIN groupuser g ON e.id = g.user_id INNER JOIN entity e2 ON e2.id = g.group_id AND e2.id = 12 WHERE e.id = 4 AND (e.type = 0 AND (e2.type = 1 OR e2.type IS NULL))'); + $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id, e2.id AS e2__id FROM entity e" + . " INNER JOIN groupuser g ON e.id = g.user_id INNER JOIN entity e2 ON e2.id = g.group_id" + . " AND e2.id = 12 WHERE e.id = 4 AND (e.type = 0 AND (e2.type = 1 OR e2.type IS NULL))"); $rs = $q->execute(); @@ -146,9 +152,11 @@ class Doctrine_Query_JoinCondition2_TestCase extends Doctrine_UnitTestCase { $q = new Doctrine_Query($this->connection); - $q->select('u.id')->from('User u')->innerJoin('u.Group g WITH g.id = ?', 12)->where('u.id = ?', 4); + $q->select('u.id, g.id')->from('User u')->innerJoin('u.Group g WITH g.id = ?', 12)->where('u.id = ?', 4); - $this->assertEqual($q->getQuery(), 'SELECT e.id AS e__id FROM entity e INNER JOIN groupuser g ON e.id = g.user_id INNER JOIN entity e2 ON e2.id = g.group_id AND e2.id = ? WHERE e.id = ? AND (e.type = 0 AND (e2.type = 1 OR e2.type IS NULL))'); + $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id, e2.id AS e2__id FROM entity e" + . " INNER JOIN groupuser g ON e.id = g.user_id INNER JOIN entity e2 ON e2.id = g.group_id" + . " AND e2.id = ? WHERE e.id = ? AND (e.type = 0 AND (e2.type = 1 OR e2.type IS NULL))"); $rs = $q->execute();