Commit e4114c47 authored by zYne's avatar zYne

fixed literal enum conversion with joins

parent 6b6daad0
......@@ -1098,8 +1098,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$path = $e[0];
}
$tmp = explode(' ', $path);
$originalAlias = (count($tmp) > 1) ? end($tmp) : null;
$tmp = explode(' ', $path);
$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
......
......@@ -126,7 +126,7 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
$field = $table->getColumnName($field);
// check if value is enumerated value
$enumIndex = $table->enumIndex($field, trim($value, "'"));
if (substr($value, 0, 1) == '(') {
// trim brackets
$trimmed = Doctrine_Tokenizer::bracketTrim($value);
......
......@@ -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()
{
// sorry, odd I know, best I can do... pookey!
try {
$q = new Doctrine_Query($this->connection);
$q->select('e.*, f.*, g.status')
->from('EnumTest e')
->innerjoin('e.Enum2 g')
->leftjoin('e.Enum3 f')
->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) {
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()
{
$q = new Doctrine_Query($this->connection);
$q->addSelect('e.*')
->addSelect('e3.*')
->from('EnumTest e')
->leftjoin('e.Enum3 e3')
->where("e.status = 'verified'")
->execute();
$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
......@@ -666,7 +666,7 @@ class NestTest extends Doctrine_Record
}
public function setUp()
{
$this->hasMany('NestTest as Parents', array('local' => 'child_id',
$this->hasMany('NestTest as Parents', array('local' => 'child_id',
'refClass' => 'NestReference',
'foreign' => 'parent_id'));
$this->hasMany('NestTest as Children', array('local' => 'parent_id',
......
......@@ -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());
......@@ -181,7 +181,7 @@ $test->addTestCase(new Doctrine_Relation_Parser_TestCase());
// Datatypes
$test->addTestCase(new Doctrine_Enum_TestCase());
$test->addTestCase(new Doctrine_Boolean_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