Bạn sẽ cần tạo chức năng Doctrine của riêng bạn để sử dụng GROUP_CONCAT;
config.yml;
orm:
dql:
string_functions:
GROUP_CONCAT: Your\Bundle\DQL\GroupConcat
\ Bundle \ DQL \ GroupConcat.php của bạn;
(nguồn: https://github.com/beberlei/DoctrineExtensions/blob/master/src/Query/Mysql/GroupConcat.php)
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
class GroupConcat extends FunctionNode
{
public $isDistinct = false;
public $expression = null;
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
{
return 'GROUP_CONCAT(' .
($this->isDistinct ? 'DISTINCT ' : '') .
$this->expression->dispatch($sqlWalker) .
')';
}
public function parse(\Doctrine\ORM\Query\Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$lexer = $parser->getLexer();
if ($lexer->isNextToken(Lexer::T_DISTINCT)) {
$parser->match(Lexer::T_DISTINCT);
$this->isDistinct = true;
}
$this->expression = $parser->SingleValuedPathExpression();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
}
Sau đó, trong xây dựng truy vấn của bạn (hoặc DQL);
$qb->select('GROUP_CONCAT(category.name)');
Nguồn
2015-07-14 20:56:20
Học thuyết không biết "group_concat" là gì, vì vậy bạn phải dạy Doctrine phải làm gì với nó. Tài liệu tại http://doctrine-orm.readthedocs.org/en/latest/cookbook/dql-user-defined-functions.html – Koalabaerchen