Commit 94005a9f authored by doctrine's avatar doctrine

DQL alias bug fixed

parent c9e345d4
......@@ -601,6 +601,7 @@ class Doctrine_Query extends Doctrine_Access {
$field = array_pop($a);
$reference = implode(".",$a);
$name = end($a);
$this->load($reference);
$tname = $this->tables[$name]->getTableName();
......@@ -788,14 +789,20 @@ class Doctrine_Query extends Doctrine_Access {
$operator = array_shift($e);
$value = implode(" ",$e);
$reference = implode(".",$a);
$objTable = $this->session->getTable(end($a));
if(count($a) > 1)
$objTable = $this->tables[$a[0]]->getForeignKey(end($a))->getTable();
else
$objTable = $this->session->getTable(end($a));
$where = $objTable->getTableName().".".$field." ".$operator." ".$value;
if(count($a) > 1 && isset($a[1])) {
$root = $a[0];
$fk = $this->tables[$root]->getForeignKey($a[1]);
if($fk instanceof Doctrine_Association) {
$asf = $fk->getAssociationFactory();
$asf = $fk->getAssociationFactory();
switch($fk->getType()):
case Doctrine_Relation::ONE_AGGREGATE:
case Doctrine_Relation::ONE_COMPOSITE:
......@@ -803,15 +810,15 @@ class Doctrine_Query extends Doctrine_Access {
break;
case Doctrine_Relation::MANY_AGGREGATE:
case Doctrine_Relation::MANY_COMPOSITE:
$b = array_shift($a);
$b = array_shift($a);
$b = $fk->getTable()->getComponentName();
$graph = new Doctrine_Query($this->session);
$graph->parseQuery("FROM $b-l WHERE $where");
$where = $this->tables[$root]->getTableName().".".$this->tables[$root]->getIdentifier()." IN (SELECT ".$fk->getLocal()." FROM ".$asf->getTableName()." WHERE ".$fk->getForeign()." IN (".$graph->getQuery()."))";
break;
endswitch;
} else
$this->load($reference);
$this->load($reference);
} else
$this->load($reference);
......
......@@ -23,7 +23,7 @@ class Doctrine_Table extends Doctrine_Configurable {
/**
* @var array $relations an array containing all the Doctrine_Relation objects for this table
*/
private $relations = array();
private $relations = array();
/**
* @var array $primaryKeys an array containing all primary key column names
*/
......
<?php
class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
public function testQueryWithAliases() {
$task = new Task();
$task->name = "Task 1";
$task->ResourceAlias[0]->name = "Resource 1";
$task->ResourceAlias[1]->name = "Resource 2";
$task->save();
$query = new Doctrine_Query($this->session);
$coll = $query->query("FROM Task WHERE Task.ResourceAlias.name = 'Resource 1'");
$this->assertEqual($coll->count(), 1);
$this->assertTrue($coll[0] instanceof Task);
}
public function testQueryArgs() {
$query = new Doctrine_Query($this->session);
$query = $query->from("User-l");
......@@ -75,7 +90,9 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this->assertEqual($users->count(),8);
$this->assertTrue($users[0]->name == "Arnold Schwarzenegger");
}
public function testQuery() {
$query = new Doctrine_Query($this->session);
$this->graph = $query;
......@@ -244,8 +261,6 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this->assertTrue($users instanceof Doctrine_Collection);
$this->assertEqual($users->count(),1);
$values = $query->query("SELECT COUNT(User.name) AS users, MAX(User.name) AS max FROM User");
$this->assertEqual(trim($query->getQuery()),"SELECT COUNT(entity.name) AS users, MAX(entity.name) AS max FROM entity WHERE (entity.type = 0)");
$this->assertTrue(is_array($values));
......
<?php
require_once("UnitTestCase.class.php");
class Doctrine_TableTestCase extends Doctrine_UnitTestCase {
public function testGetIdentifier() {
$table = $this->session->getTable("User");
}
......@@ -27,7 +28,7 @@ class Doctrine_TableTestCase extends Doctrine_UnitTestCase {
$this->assertTrue($fk->getLocal() == $this->objTable->getIdentifier());
$this->assertTrue($fk->getForeign() == "entity_id");
}
public function testGetComponentName() {
$this->assertTrue($this->objTable->getComponentName() == "User");
......
......@@ -98,6 +98,7 @@ class Phonenumber extends Doctrine_Record {
$this->hasColumn("entity_id","integer");
}
}
class Element extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn("name", "string", 100);
......
......@@ -27,13 +27,13 @@ $test = new GroupTest("Doctrine Framework Unit Tests");
$test->addTestCase(new Doctrine_TableTestCase());
$test->addTestCase(new Doctrine_SessionTestCase());
$test->addTestCase(new Doctrine_RecordTestCase());
$test->addTestCase(new Doctrine_TableTestCase());
$test->addTestCase(new Doctrine_ValidatorTestCase());
......@@ -54,7 +54,6 @@ $test->addTestCase(new Doctrine_Collection_OffsetTestCase());
$test->addTestCase(new Sensei_UnitTestCase());
$test->addTestCase(new Doctrine_QueryTestCase());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
......
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