diff --git a/classes/Query.class.php b/classes/Query.class.php index 80b527146..56329d434 100644 --- a/classes/Query.class.php +++ b/classes/Query.class.php @@ -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; } } diff --git a/classes/Session/Mysql.class.php b/classes/Session/Mysql.class.php index e320ccd1c..223cca445 100644 --- a/classes/Session/Mysql.class.php +++ b/classes/Session/Mysql.class.php @@ -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) { diff --git a/tests/QueryTestCase.class.php b/tests/QueryTestCase.class.php index a17516b31..900dab6d4 100644 --- a/tests/QueryTestCase.class.php +++ b/tests/QueryTestCase.class.php @@ -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)"); diff --git a/tests/run.php b/tests/run.php index b4f6e8b6c..d7b5ba035 100644 --- a/tests/run.php +++ b/tests/run.php @@ -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 "
";
 $test->run(new HtmlReporter());
 $cache = Doctrine_Manager::getInstance()->getCurrentSession()->getCacheHandler();