Commit ced9625b authored by doctrine's avatar doctrine

DQL : INNER and OUTER JOIN switching with ':' and '.' operators

parent 30a00c50
......@@ -858,45 +858,48 @@ class Doctrine_Query extends Doctrine_Access {
* @throws DQLException
*/
final public function load($path, $fetchmode = Doctrine::FETCH_LAZY) {
$e = explode(".",$path);
$e = preg_split("/[.:]/",$path);
$index = 0;
foreach($e as $key => $name) {
try {
if($key == 0) {
$objTable = $this->session->getTable($name);
$table = $this->session->getTable($name);
if(count($e) == 1) {
$tname = $objTable->getTableName();
$tname = $table->getTableName();
$this->parts["from"][$tname] = true;
}
} else {
$fk = $objTable->getForeignKey($name);
$index += strlen($e[($key - 1)]) + 1;
// the mark here is either '.' or ':'
$mark = substr($path,($index - 1),1);
$fk = $table->getForeignKey($name);
$name = $fk->getTable()->getComponentName();
$tname = $objTable->getTableName();
$next = $fk->getTable();
$tname2 = $next->getTableName();
$tname = $table->getTableName();
$tname2 = $fk->getTable()->getTableName();
$this->connectors[$name] = $fk;
if($fk instanceof Doctrine_ForeignKey ||
$fk instanceof Doctrine_LocalKey) {
switch($fk->getType()):
case Doctrine_Relation::ONE_AGGREGATE:
case Doctrine_Relation::ONE_COMPOSITE:
//$this->parts["where"][] = "(".$tname.".".$fk->getLocal()." = ".$tname2.".".$fk->getForeign().")";
//$this->parts["from"][$tname] = true;
//$this->parts["from"][$tname2] = true;
switch($mark):
case ":":
$this->parts["join"][$tname] = "INNER JOIN ".$tname2." ON ".$tname.".".$fk->getLocal()." = ".$tname2.".".$fk->getForeign();
break;
case Doctrine_Relation::MANY_AGGREGATE:
case Doctrine_Relation::MANY_COMPOSITE:
case ".":
$this->parts["join"][$tname] = "LEFT JOIN ".$tname2." ON ".$tname.".".$fk->getLocal()." = ".$tname2.".".$fk->getForeign();
$this->joined[] = $tname2;
break;
endswitch;
$c = $objTable->getComponentName();
$c = $table->getComponentName();
$this->joins[$name] = $c;
} elseif($fk instanceof Doctrine_Association) {
$asf = $fk->getAssociationFactory();
......@@ -915,11 +918,11 @@ class Doctrine_Query extends Doctrine_Access {
endswitch;
}
$objTable = $next;
$table = $fk->getTable();
}
if( ! isset($this->tables[$name])) {
$this->tables[$name] = $objTable;
$this->tables[$name] = $table;
}
} catch(Exception $e) {
......@@ -927,7 +930,7 @@ class Doctrine_Query extends Doctrine_Access {
throw new DQLException($e->getMessage(),$e->getCode());
}
}
return $objTable;
return $table;
}
}
......
......@@ -3,11 +3,19 @@
* mysql driver
*/
class Doctrine_Session_Mysql extends Doctrine_Session_Common {
/**
* the constructor
* @param PDO $pdo -- database handle
*/
public function __construct(Doctrine_Manager $manager,PDO $pdo) {
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
parent::__construct($manager,$pdo);
}
/**
* deletes all data access object from the collection
* @param Doctrine_Collection $coll
*/
/**
public function deleteCollection(Doctrine_Collection $coll) {
......
......@@ -160,7 +160,7 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$query->from("User-b")->orderby("User.name ASC, User.Email.address");
$users = $query->execute();
$this->assertEqual(trim($query->getQuery()),
"SELECT entity.id AS User__id FROM entity INNER JOIN email ON entity.email_id = email.id WHERE (entity.type = 0) ORDER BY entity.name ASC, email.address");
"SELECT entity.id AS User__id FROM entity LEFT JOIN email ON entity.email_id = email.id WHERE (entity.type = 0) ORDER BY entity.name ASC, email.address");
$this->assertEqual($users->count(),8);
$this->assertTrue($users[0]->name == "Arnold Schwarzenegger");
}
......@@ -301,7 +301,7 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$users = $query->query("FROM User-b, User.Email-b");
$users = $query->query("FROM User-b, User:Email-b");
$this->assertEqual(trim($query->getQuery()),
"SELECT entity.id AS User__id, email.id AS Email__id FROM entity INNER JOIN email ON entity.email_id = email.id WHERE (entity.type = 0)");
......
......@@ -18,7 +18,6 @@ require_once("CollectionOffsetTestCase.class.php");
require_once("SenseiTestCase.class.php");
require_once("QueryTestCase.class.php");
error_reporting(E_ALL);
$test = new GroupTest("Doctrine Framework Unit Tests");
......@@ -55,9 +54,6 @@ $test->addTestCase(new Doctrine_QueryTestCase());
print "<pre>";
$test->run(new HtmlReporter());
$cache = Doctrine_Manager::getInstance()->getCurrentSession()->getCacheHandler();
......
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