From 5957622575a0e27cc90c394face27770474f1ad9 Mon Sep 17 00:00:00 2001 From: zYne Date: Tue, 10 Oct 2006 18:09:20 +0000 Subject: [PATCH] Fixes #157 Ticket: 157 --- lib/Doctrine/Hydrate.php | 5 ++++- lib/Doctrine/Query.php | 12 +++++++----- tests/QueryWhereTestCase.php | 13 +++++++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/Hydrate.php b/lib/Doctrine/Hydrate.php index 445d7dd38..52494423c 100644 --- a/lib/Doctrine/Hydrate.php +++ b/lib/Doctrine/Hydrate.php @@ -204,7 +204,10 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { * @param string $path * @return string */ - final public function getTableAlias($path) { + final public function getTableAlias($path) { + if(isset($this->compAliases[$path])) + $path = $this->compAliases[$path]; + if( ! isset($this->tableAliases[$path])) return false; diff --git a/lib/Doctrine/Query.php b/lib/Doctrine/Query.php index fd6061833..78e70a98a 100644 --- a/lib/Doctrine/Query.php +++ b/lib/Doctrine/Query.php @@ -650,14 +650,13 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable { } return $term; } - /** * generateAlias * * @param string $tableName * @return string */ - final public function generateAlias($tableName) { + public function generateAlias($tableName) { if(isset($this->tableIndexes[$tableName])) { return $tableName.++$this->tableIndexes[$tableName]; } else { @@ -688,9 +687,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable { } else $path = $tmp[0]; - if($componentAlias !== false) { - $this->compAliases[$componentAlias] = $path; - } + $index = 0; $currPath = ''; @@ -816,6 +813,11 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable { throw new Doctrine_Query_Exception($e->__toString()); } } + + if($componentAlias !== false) { + $this->compAliases[$componentAlias] = $currPath; + } + return $table; } /** diff --git a/tests/QueryWhereTestCase.php b/tests/QueryWhereTestCase.php index 7ea1c5a00..c4ad36a01 100644 --- a/tests/QueryWhereTestCase.php +++ b/tests/QueryWhereTestCase.php @@ -5,6 +5,7 @@ class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase { $this->tables = array('entity'); parent::prepareTables(); } + public function testDirectParameterSetting() { $this->connection->clear(); @@ -36,6 +37,18 @@ class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase { $this->assertEqual($users[0]->name, 'someone'); $this->assertEqual($users[1]->name, 'someone.2'); } + public function testComponentAliases() { + $q = new Doctrine_Query(); + + $q = new Doctrine_Query(); + + $q->from('User(id) u')->addWhere('u.id IN (?, ?)',array(1,2)); + $users = $q->execute(); + + $this->assertEqual($users->count(), 2); + $this->assertEqual($users[0]->name, 'someone'); + $this->assertEqual($users[1]->name, 'someone.2'); + } public function testOperatorWithNoTrailingSpaces() { $q = new Doctrine_Query();