From b6e8c40067910dc449959a9b23fea476ba548ed4 Mon Sep 17 00:00:00 2001 From: zYne Date: Tue, 23 Jan 2007 16:40:46 +0000 Subject: [PATCH] column alias support for DQL HAVING part --- lib/Doctrine/Query/Having.php | 3 ++- tests/ColumnAliasTestCase.php | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/Query/Having.php b/lib/Doctrine/Query/Having.php index 6c4652273..8e8d5c4a7 100644 --- a/lib/Doctrine/Query/Having.php +++ b/lib/Doctrine/Query/Having.php @@ -63,7 +63,8 @@ class Doctrine_Query_Having extends Doctrine_Query_Condition $field = array_pop($a); $reference = implode('.', $a); $table = $this->query->load($reference, false); - $func = $this->query->getTableAlias($reference).".".$field; + $field = $table->getColumnName($field); + $func = $this->query->getTableAlias($reference) . '.' . $field; return $func; } else { diff --git a/tests/ColumnAliasTestCase.php b/tests/ColumnAliasTestCase.php index 8829b19e2..78bf4d1aa 100644 --- a/tests/ColumnAliasTestCase.php +++ b/tests/ColumnAliasTestCase.php @@ -75,6 +75,30 @@ class Doctrine_ColumnAlias_TestCase extends Doctrine_UnitTestCase $this->assertEqual($coll[0]->alias1, 'someone'); $this->assertEqual($coll[0]->alias2, 187); } + public function testAliasesAreSupportedForDqlAggregateFunctions() + { + $q = new Doctrine_Query(); + + $q->select('MAX(c.alias1)') + ->from('ColumnAliasTest c'); + + $coll = $q->execute(); + + $this->assertEqual($coll[0]->max, 'someone'); + } + public function testAliasesAreSupportedForDqlHavingPart() + { + $q = new Doctrine_Query(); + + $q->select('c.alias1') + ->from('ColumnAliasTest c') + ->having('MAX(c.alias2) = 187') + ->groupby('c.id'); + + $coll = $q->execute(); + + $this->assertEqual($coll[0]->alias1, 'someone'); + } } class ColumnAliasTest extends Doctrine_Record {