Commit 2592739f authored by zYne's avatar zYne

--no commit message

--no commit message
parent 6a7130be
...@@ -88,7 +88,7 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable ...@@ -88,7 +88,7 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable
*/ */
public static function create() public static function create()
{ {
return new Doctrine_Query(); return new Doctrine_Query2();
} }
/** /**
* isSubquery * isSubquery
...@@ -604,7 +604,7 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable ...@@ -604,7 +604,7 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable
if ( ! in_array($e[3], $this->subqueryAliases) && if ( ! in_array($e[3], $this->subqueryAliases) &&
! in_array($e[2], $this->subqueryAliases)) { ! in_array($e[2], $this->subqueryAliases)) {
continue; continue;
} }
} }
$subquery .= ' ' . $part; $subquery .= ' ' . $part;
...@@ -789,8 +789,8 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable ...@@ -789,8 +789,8 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable
$path = $e[0]; $path = $e[0];
} }
$tmp = explode(' ', $path); $tmp = explode(' ', $path);
$componentAlias = (count($tmp) > 1) ? end($tmp) : false; $originalAlias = (count($tmp) > 1) ? end($tmp) : null;
$e = preg_split("/[.:]/", $tmp[0], -1); $e = preg_split("/[.:]/", $tmp[0], -1);
...@@ -814,26 +814,28 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable ...@@ -814,26 +814,28 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable
$delimeter = substr($fullPath, $length, 1); $delimeter = substr($fullPath, $length, 1);
// if an alias is not given use the current path as an alias identifier // if an alias is not given use the current path as an alias identifier
if (strlen($prevPath) !== $fullLength || ! $componentAlias) { if (strlen($prevPath) === $fullLength && isset($originalAlias)) {
$componentAlias = $originalAlias;
} else {
$componentAlias = $prevPath; $componentAlias = $prevPath;
} }
if ( ! isset($table)) { if ( ! isset($table)) {
// process the root of the path // process the root of the path
$table = $this->loadRoot($name, $componentAlias); $table = $this->loadRoot($name, $componentAlias);
} else { } else {
$join = ($delimeter == ':') ? 'INNER JOIN ' : 'LEFT JOIN '; $join = ($delimeter == ':') ? 'INNER JOIN ' : 'LEFT JOIN ';
$relation = $table->getRelation($name); $relation = $table->getRelation($name);
$this->_aliasMap[$componentAlias] = array('table' => $relation->getTable(), $this->_aliasMap[$componentAlias] = array('table' => $relation->getTable(),
'parent' => $parent, 'parent' => $parent,
'relation' => $relation); 'relation' => $relation);
if( ! $relation->isOneToOne()) { if ( ! $relation->isOneToOne()) {
$this->needsSubquery = true; $this->needsSubquery = true;
} }
$localAlias = $this->getShortAlias($parent, $table->getTableName()); $localAlias = $this->getShortAlias($parent, $table->getTableName());
$foreignAlias = $this->getShortAlias($componentAlias, $relation->getTable()->getTableName()); $foreignAlias = $this->getShortAlias($componentAlias, $relation->getTable()->getTableName());
$localSql = $this->conn->quoteIdentifier($table->getTableName()) . ' ' . $localAlias; $localSql = $this->conn->quoteIdentifier($table->getTableName()) . ' ' . $localAlias;
...@@ -880,6 +882,7 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable ...@@ -880,6 +882,7 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable
} }
} else { } else {
$queryPart = $join . $foreignSql $queryPart = $join . $foreignSql
. ' ON ' . $localAlias . '.' . ' ON ' . $localAlias . '.'
. $relation->getLocal() . ' = ' . $foreignAlias . '.' . $relation->getForeign() . $relation->getLocal() . ' = ' . $foreignAlias . '.' . $relation->getForeign()
...@@ -913,6 +916,7 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable ...@@ -913,6 +916,7 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable
$this->pendingAggregates = array(); $this->pendingAggregates = array();
} }
} }
$parent = $prevPath;
} }
return end($this->_aliasMap); return end($this->_aliasMap);
} }
...@@ -1020,7 +1024,7 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable ...@@ -1020,7 +1024,7 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable
*/ */
public function query($query, $params = array()) public function query($query, $params = array())
{ {
$this->_parser->parseQuery($query); $this->parseQuery($query);
return $this->execute($params); return $this->execute($params);
} }
......
...@@ -192,11 +192,11 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase ...@@ -192,11 +192,11 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
$q->from('User.Phonenumber'); $q->from('User.Phonenumber');
$q->where('User.name = ?'); $q->where('User.name = ?');
$q->limit(5); $q->limit(5);
print $q;
$users = $q->execute(array('zYne')); $users = $q->execute(array('zYne'));
$this->assertEqual($users->count(), 1); $this->assertEqual($users->count(), 1);
$this->connection->flush(); //$this->connection->flush();
} }
public function testLimitWithManyToManyColumnAggInheritanceLeftJoin() public function testLimitWithManyToManyColumnAggInheritanceLeftJoin()
{ {
...@@ -204,7 +204,6 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase ...@@ -204,7 +204,6 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
$q->from('User.Group')->limit(5); $q->from('User.Group')->limit(5);
$users = $q->execute(); $users = $q->execute();
$this->assertEqual($users->count(), 5); $this->assertEqual($users->count(), 5);
...@@ -219,7 +218,8 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase ...@@ -219,7 +218,8 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
$user3->Group = $user->Group; $user3->Group = $user->Group;
$this->assertEqual($user->Group[0]->name, "Action Actors"); $this->assertEqual($user->Group[0]->name, "Action Actors");
$this->assertEqual(count($user->Group), 3);
$this->connection->flush(); $this->connection->flush();
$this->assertEqual($user->Group[0]->name, "Action Actors"); $this->assertEqual($user->Group[0]->name, "Action Actors");
...@@ -236,8 +236,8 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase ...@@ -236,8 +236,8 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($users->count(), 3); $this->assertEqual($users->count(), 3);
$this->connection->clear(); $this->connection->clear();
$q = new Doctrine_Query(); $q = new Doctrine_Query2();
$q->from("User")->where("User.Group.id = ?")->orderby("User.id DESC"); $q->from('User')->where('User.Group.id = ?')->orderby('User.id DESC');
$users = $q->execute(array($user->Group[1]->id)); $users = $q->execute(array($user->Group[1]->id));
$this->assertEqual($users->count(), 3); $this->assertEqual($users->count(), 3);
...@@ -287,6 +287,5 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase ...@@ -287,6 +287,5 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($q->getQuery(), $this->assertEqual($q->getQuery(),
"SELECT p.id AS p__id, p.name AS p__name FROM photo p LEFT JOIN phototag p2 ON p.id = p2.photo_id LEFT JOIN tag t ON t.id = p2.tag_id WHERE p.id IN (SELECT DISTINCT p3.id FROM photo p3 LEFT JOIN phototag p4 ON p3.id = p4.photo_id LEFT JOIN tag t2 ON t2.id = p4.tag_id WHERE t2.id = ? ORDER BY p3.id DESC LIMIT 100) AND t.id = ? ORDER BY p.id DESC"); "SELECT p.id AS p__id, p.name AS p__name FROM photo p LEFT JOIN phototag p2 ON p.id = p2.photo_id LEFT JOIN tag t ON t.id = p2.tag_id WHERE p.id IN (SELECT DISTINCT p3.id FROM photo p3 LEFT JOIN phototag p4 ON p3.id = p4.photo_id LEFT JOIN tag t2 ON t2.id = p4.tag_id WHERE t2.id = ? ORDER BY p3.id DESC LIMIT 100) AND t.id = ? ORDER BY p.id DESC");
} }
} }
?> ?>
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