Commit 62860d51 authored by romanb's avatar romanb

fixed joincondition tests.

parent a6e84aee
...@@ -61,7 +61,6 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract ...@@ -61,7 +61,6 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
public function hydrateResultSet($stmt, $tableAliases, $hydrationMode = null) public function hydrateResultSet($stmt, $tableAliases, $hydrationMode = null)
{ {
//$s = microtime(true); //$s = microtime(true);
$this->_tableAliases = $tableAliases; $this->_tableAliases = $tableAliases;
if ($hydrationMode == Doctrine::HYDRATE_NONE) { if ($hydrationMode == Doctrine::HYDRATE_NONE) {
...@@ -284,7 +283,7 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract ...@@ -284,7 +283,7 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
protected function _gatherRowData(&$data, &$cache, &$id, &$nonemptyComponents) protected function _gatherRowData(&$data, &$cache, &$id, &$nonemptyComponents)
{ {
$rowData = array(); $rowData = array();
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
// Parse each column name only once. Cache the results. // Parse each column name only once. Cache the results.
if ( ! isset($cache[$key])) { if ( ! isset($cache[$key])) {
......
...@@ -481,7 +481,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria ...@@ -481,7 +481,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
public function processPendingFields($componentAlias) public function processPendingFields($componentAlias)
{ {
$tableAlias = $this->getTableAlias($componentAlias); $tableAlias = $this->getTableAlias($componentAlias);
$table = $this->_queryComponents[$componentAlias]['table']; $table = $this->_queryComponents[$componentAlias]['table'];
if ( ! isset($this->_pendingFields[$componentAlias])) { if ( ! isset($this->_pendingFields[$componentAlias])) {
return; return;
...@@ -1610,8 +1610,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria ...@@ -1610,8 +1610,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
$this->_pendingJoinConditions[$componentAlias] = $joinCondition; $this->_pendingJoinConditions[$componentAlias] = $joinCondition;
} }
} }
if ($loadFields) {
if ($loadFields) {
$restoreState = false; $restoreState = false;
// load fields if necessary // load fields if necessary
if ($loadFields && empty($this->_dqlParts['select'])) { if ($loadFields && empty($this->_dqlParts['select'])) {
......
...@@ -910,7 +910,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count ...@@ -910,7 +910,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
* @return Doctrine_Record * @return Doctrine_Record
*/ */
public function set($fieldName, $value, $load = true) public function set($fieldName, $value, $load = true)
{ {
if (isset($this->_data[$fieldName])) { if (isset($this->_data[$fieldName])) {
if ($value instanceof Doctrine_Record) { if ($value instanceof Doctrine_Record) {
$type = $this->_table->getTypeOf($fieldName); $type = $this->_table->getTypeOf($fieldName);
......
...@@ -54,20 +54,22 @@ class Doctrine_Query_JoinCondition2_TestCase extends Doctrine_UnitTestCase ...@@ -54,20 +54,22 @@ class Doctrine_Query_JoinCondition2_TestCase extends Doctrine_UnitTestCase
$groups->save(); $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[0] = $groups[0];
$zYne->Group[1] = $groups[1]; $zYne->Group[1] = $groups[1];
$zYne->save(); $zYne->save();
} }
public function testJoinCondifitionsRawLeftJoins() public function testJoinConditionsRawLeftJoins()
{ {
$q = Doctrine_Query::create(); $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(); $rs = $q->execute();
...@@ -88,13 +90,15 @@ class Doctrine_Query_JoinCondition2_TestCase extends Doctrine_UnitTestCase ...@@ -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 = 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(); $rs = $q->execute();
...@@ -115,13 +119,15 @@ class Doctrine_Query_JoinCondition2_TestCase extends Doctrine_UnitTestCase ...@@ -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 = 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(); $rs = $q->execute();
...@@ -146,9 +152,11 @@ class Doctrine_Query_JoinCondition2_TestCase extends Doctrine_UnitTestCase ...@@ -146,9 +152,11 @@ class Doctrine_Query_JoinCondition2_TestCase extends Doctrine_UnitTestCase
{ {
$q = new Doctrine_Query($this->connection); $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(); $rs = $q->execute();
......
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