diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 63351a89a..4caee210c 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -2390,7 +2390,7 @@ class Parser $functionName = $this->_lexer->token['value']; $this->match(Lexer::T_OPEN_PARENTHESIS); - $pathExp = $this->StateFieldPathExpression(); + $pathExp = $this->SimpleArithmeticExpression(); $this->match(Lexer::T_CLOSE_PARENTHESIS); } diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index d94d50b30..5be2ee287 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -1243,7 +1243,7 @@ class SqlWalker implements TreeWalker public function walkAggregateExpression($aggExpression) { return $aggExpression->functionName . '(' . ($aggExpression->isDistinct ? 'DISTINCT ' : '') - . $this->walkPathExpression($aggExpression->pathExpression) . ')'; + . $this->walkSimpleArithmeticExpression($aggExpression->pathExpression) . ')'; } /** diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index ecc32fe56..7b9cb4815 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -209,6 +209,14 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ); } + public function testSupportsAggregateFunctionWithSimpleArithmetic() + { + $this->assertSqlGeneration( + 'SELECT MAX(u.id + 4) * 2 FROM Doctrine\Tests\Models\CMS\CmsUser u', + 'SELECT MAX(c0_.id + 4) * 2 AS sclr0 FROM cms_users c0_' + ); + } + public function testSupportsWhereClauseWithPositionalParameter() { $this->assertSqlGeneration(