modifiye @Ocramius kodu.
içinde bu kod parçası koyun:
<?php
namespace YourApp\YourMainBundle\DoctrineFunctions;
use Doctrine\ORM\Query\AST\Functions\FunctionNode,
Doctrine\ORM\Query\Lexer;
class Round extends FunctionNode
{
private $arithmeticExpression;
public function parse(\Doctrine\ORM\Query\Parser $parser)
{
$lexer = $parser->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) . ')';
}
}
Sonra app/config/config.yml
bu koymak: Round.php
dosya adı olarak src/YourNamespace/YourMainBundle/DoctrineFunctions/
dizinde size doğrudan ROUND()
fonksiyonunu kullanmasına izin vereceğini
doctrine:
dql:
numeric_functions:
round: YourApp\YourMainBundle\DoctrineFunctions\Round
DQL SELECT sorgularınız; QueryBuilder ile veya doğrudan createQuery()
Evet bunu yapmak için tek yol gibi görünüyor. Yol tariflerini takdir ediyorum. – Shawn