Commit e4114c47 authored by zYne's avatar zYne

fixed literal enum conversion with joins

parent 6b6daad0
......@@ -1099,7 +1099,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
}
$tmp = explode(' ', $path);
$originalAlias = (count($tmp) > 1) ? end($tmp) : null;
$componentAlias = $originalAlias = (count($tmp) > 1) ? end($tmp) : null;
$e = preg_split("/[.:]/", $tmp[0], -1);
......@@ -1109,6 +1109,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
if (isset($this->_aliasMap[$e[0]])) {
$table = $this->_aliasMap[$e[0]]['table'];
$componentAlias = $e[0];
$prevPath = $parent = array_shift($e);
}
......@@ -1229,11 +1230,6 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
if(isset($this->pendingFields[$componentAlias])) {
$this->processPendingFields($componentAlias);
}
/**
if(isset($this->pendingAggregates[$componentAlias]) || isset($this->pendingAggregates[0])) {
$this->processPendingAggregates($componentAlias);
}
*/
if ($restoreState) {
$this->pendingFields = array();
......@@ -1242,7 +1238,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
}
$parent = $prevPath;
}
return end($this->_aliasMap);
return $this->_aliasMap[$componentAlias];
}
/**
* loadRoot
......
......@@ -39,7 +39,7 @@ class Doctrine_Enum_TestCase extends Doctrine_UnitTestCase
$this->tables = array("EnumTest", "EnumTest2", "EnumTest3");
parent::prepareTables();
}
/**
public function testParameterConversion()
{
$test = new EnumTest();
......@@ -66,17 +66,7 @@ class Doctrine_Enum_TestCase extends Doctrine_UnitTestCase
}
}
public function testEnumFetchArray() {
$q = new Doctrine_Query();
$q->select('e.*')
->from('EnumTest e')
->limit(1);
$ret = $q->execute(array(), Doctrine::FETCH_ARRAY);
if (is_numeric($ret[0]['status']))
{
$this->fail();
}
}
public function testInAndNotIn()
{
......@@ -117,7 +107,7 @@ class Doctrine_Enum_TestCase extends Doctrine_UnitTestCase
$this->fail();
}
}
*/
public function testEnumType()
{
......@@ -183,22 +173,30 @@ class Doctrine_Enum_TestCase extends Doctrine_UnitTestCase
$this->assertTrue($f);
}
public function testEnumWithLeftJoin()
public function testEnumFetchArray() {
$q = new Doctrine_Query();
$q->select('e.*')
->from('EnumTest e')
->limit(1);
$ret = $q->execute(array(), Doctrine::FETCH_ARRAY);
if (is_numeric($ret[0]['status'])) {
$this->fail();
}
}
public function testLiteralEnumValueConversionSupportsJoins()
{
// sorry, odd I know, best I can do... pookey!
try {
$q = new Doctrine_Query($this->connection);
$q->select('e.*, f.*, g.status')
$q->addSelect('e.*')
->addSelect('e3.*')
->from('EnumTest e')
->innerjoin('e.Enum2 g')
->leftjoin('e.Enum3 f')
->leftjoin('e.Enum3 e3')
->where("e.status = 'verified'")
->limit(1)
->execute();
$this->assertNotEqual($q->getQuery(), "SELECT e.id AS e__id, e.status AS e__status, e.text AS e__text, e2.id AS e2__id, e2.status AS e2__status, e3.text AS e3__text FROM enum_test e INNER JOIN enum_test2 e2 ON e.id = e2.enum_test_id LEFT JOIN enum_test3 e3 ON e.text = e3.text WHERE e.id IN (SELECT DISTINCT e4.id FROM enum_test e4 INNER JOIN enum_test2 e5 ON e4.id = e5.enum_test_id LEFT JOIN enum_test3 e6 ON e4.text = e6.text WHERE e4.status = 'verified' LIMIT 1) AND e.status = 'verified'");
} catch (Exception $e) {
$this->fail();
}
$this->assertEqual($q->getQuery(), "SELECT e.id AS e__id, e.status AS e__status, e.text AS e__text, e2.text AS e2__text FROM enum_test e LEFT JOIN enum_test3 e2 ON e.text = e2.text WHERE e.status = 1");
}
}
?>
......@@ -417,8 +417,8 @@ class EnumTest extends Doctrine_Record
$this->hasColumn('text', 'string');
}
public function setUp() {
$this->ownsMany('EnumTest2 as Enum2', array('local' => 'id', 'foreign' => 'enum_test_id'));
$this->ownsMany('EnumTest3 as Enum3', array('local' => 'text', 'foreign' => 'text'));
$this->hasMany('EnumTest2 as Enum2', array('local' => 'id', 'foreign' => 'enum_test_id'));
$this->hasMany('EnumTest3 as Enum3', array('local' => 'text', 'foreign' => 'text'));
}
}
class EnumTest2 extends Doctrine_Record
......
......@@ -70,7 +70,7 @@ $test = new GroupTest('Doctrine Framework Unit Tests');
$test->addTestCase(new Doctrine_Ticket330_TestCase());
*/
/***/
/** */
// Connection drivers (not yet fully tested)
$test->addTestCase(new Doctrine_Connection_Pgsql_TestCase());
$test->addTestCase(new Doctrine_Connection_Oracle_TestCase());
......
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