DQL : INNER and OUTER JOIN switching with ':' and '.' operators
This commit is contained in:
parent
30a00c5060
commit
ced9625b64
@ -858,45 +858,48 @@ class Doctrine_Query extends Doctrine_Access {
|
|||||||
* @throws DQLException
|
* @throws DQLException
|
||||||
*/
|
*/
|
||||||
final public function load($path, $fetchmode = Doctrine::FETCH_LAZY) {
|
final public function load($path, $fetchmode = Doctrine::FETCH_LAZY) {
|
||||||
$e = explode(".",$path);
|
$e = preg_split("/[.:]/",$path);
|
||||||
|
$index = 0;
|
||||||
foreach($e as $key => $name) {
|
foreach($e as $key => $name) {
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if($key == 0) {
|
if($key == 0) {
|
||||||
|
|
||||||
$objTable = $this->session->getTable($name);
|
$table = $this->session->getTable($name);
|
||||||
if(count($e) == 1) {
|
if(count($e) == 1) {
|
||||||
$tname = $objTable->getTableName();
|
$tname = $table->getTableName();
|
||||||
$this->parts["from"][$tname] = true;
|
$this->parts["from"][$tname] = true;
|
||||||
}
|
}
|
||||||
} else {
|
} 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();
|
$name = $fk->getTable()->getComponentName();
|
||||||
|
|
||||||
$tname = $objTable->getTableName();
|
$tname = $table->getTableName();
|
||||||
$next = $fk->getTable();
|
|
||||||
$tname2 = $next->getTableName();
|
$tname2 = $fk->getTable()->getTableName();
|
||||||
|
|
||||||
$this->connectors[$name] = $fk;
|
$this->connectors[$name] = $fk;
|
||||||
|
|
||||||
if($fk instanceof Doctrine_ForeignKey ||
|
if($fk instanceof Doctrine_ForeignKey ||
|
||||||
$fk instanceof Doctrine_LocalKey) {
|
$fk instanceof Doctrine_LocalKey) {
|
||||||
switch($fk->getType()):
|
|
||||||
case Doctrine_Relation::ONE_AGGREGATE:
|
switch($mark):
|
||||||
case Doctrine_Relation::ONE_COMPOSITE:
|
case ":":
|
||||||
//$this->parts["where"][] = "(".$tname.".".$fk->getLocal()." = ".$tname2.".".$fk->getForeign().")";
|
|
||||||
//$this->parts["from"][$tname] = true;
|
|
||||||
//$this->parts["from"][$tname2] = true;
|
|
||||||
$this->parts["join"][$tname] = "INNER JOIN ".$tname2." ON ".$tname.".".$fk->getLocal()." = ".$tname2.".".$fk->getForeign();
|
$this->parts["join"][$tname] = "INNER JOIN ".$tname2." ON ".$tname.".".$fk->getLocal()." = ".$tname2.".".$fk->getForeign();
|
||||||
break;
|
break;
|
||||||
case Doctrine_Relation::MANY_AGGREGATE:
|
case ".":
|
||||||
case Doctrine_Relation::MANY_COMPOSITE:
|
|
||||||
$this->parts["join"][$tname] = "LEFT JOIN ".$tname2." ON ".$tname.".".$fk->getLocal()." = ".$tname2.".".$fk->getForeign();
|
$this->parts["join"][$tname] = "LEFT JOIN ".$tname2." ON ".$tname.".".$fk->getLocal()." = ".$tname2.".".$fk->getForeign();
|
||||||
|
|
||||||
$this->joined[] = $tname2;
|
|
||||||
break;
|
break;
|
||||||
endswitch;
|
endswitch;
|
||||||
$c = $objTable->getComponentName();
|
|
||||||
|
$c = $table->getComponentName();
|
||||||
$this->joins[$name] = $c;
|
$this->joins[$name] = $c;
|
||||||
} elseif($fk instanceof Doctrine_Association) {
|
} elseif($fk instanceof Doctrine_Association) {
|
||||||
$asf = $fk->getAssociationFactory();
|
$asf = $fk->getAssociationFactory();
|
||||||
@ -915,11 +918,11 @@ class Doctrine_Query extends Doctrine_Access {
|
|||||||
endswitch;
|
endswitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
$objTable = $next;
|
$table = $fk->getTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ! isset($this->tables[$name])) {
|
if( ! isset($this->tables[$name])) {
|
||||||
$this->tables[$name] = $objTable;
|
$this->tables[$name] = $table;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch(Exception $e) {
|
} catch(Exception $e) {
|
||||||
@ -927,7 +930,7 @@ class Doctrine_Query extends Doctrine_Access {
|
|||||||
throw new DQLException($e->getMessage(),$e->getCode());
|
throw new DQLException($e->getMessage(),$e->getCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $objTable;
|
return $table;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,11 +3,19 @@
|
|||||||
* mysql driver
|
* mysql driver
|
||||||
*/
|
*/
|
||||||
class Doctrine_Session_Mysql extends Doctrine_Session_Common {
|
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
|
* deletes all data access object from the collection
|
||||||
* @param Doctrine_Collection $coll
|
* @param Doctrine_Collection $coll
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
public function deleteCollection(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");
|
$query->from("User-b")->orderby("User.name ASC, User.Email.address");
|
||||||
$users = $query->execute();
|
$users = $query->execute();
|
||||||
$this->assertEqual(trim($query->getQuery()),
|
$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->assertEqual($users->count(),8);
|
||||||
$this->assertTrue($users[0]->name == "Arnold Schwarzenegger");
|
$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()),
|
$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)");
|
"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("SenseiTestCase.class.php");
|
||||||
require_once("QueryTestCase.class.php");
|
require_once("QueryTestCase.class.php");
|
||||||
|
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
$test = new GroupTest("Doctrine Framework Unit Tests");
|
$test = new GroupTest("Doctrine Framework Unit Tests");
|
||||||
@ -55,9 +54,6 @@ $test->addTestCase(new Doctrine_QueryTestCase());
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
print "<pre>";
|
print "<pre>";
|
||||||
$test->run(new HtmlReporter());
|
$test->run(new HtmlReporter());
|
||||||
$cache = Doctrine_Manager::getInstance()->getCurrentSession()->getCacheHandler();
|
$cache = Doctrine_Manager::getInstance()->getCurrentSession()->getCacheHandler();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user