I know from the documentation at: http://docs.doctrine-project.org/en/2.1/reference/dql-doctrine-query-language.html#dql-functions that there is no ROUND function but is the
A bit cleaner approach would be using slightly modified @Ocramius code.
Put this piece of code in: src/YourNamespace/YourMainBundle/DoctrineFunctions/
directory as the Round.php
filename:
getLexer();
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$this->arithmeticExpression = $parser->SimpleArithmeticExpression();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
{
return 'ROUND(' . $sqlWalker->walkSimpleArithmeticExpression($this->arithmeticExpression) . ')';
}
}
Then put this in your app/config/config.yml
:
doctrine:
dql:
numeric_functions:
round: YourApp\YourMainBundle\DoctrineFunctions\Round
That would allow you to use the ROUND()
function directly in your DQL SELECT queries; no matter if done with QueryBuilder or directly via createQuery()