You will need to create your own Doctrine function to use GROUP_CONCAT;
config.yml;
orm:
dql:
string_functions:
GROUP_CONCAT: YourBundleDQLGroupConcat
YourBundleDQLGroupConcat.php;
(source: https://github.com/beberlei/DoctrineExtensions/blob/master/src/Query/Mysql/GroupConcat.php)
use DoctrineORMQueryLexer;
use DoctrineORMQueryASTFunctionsFunctionNode;
class GroupConcat extends FunctionNode
{
public $isDistinct = false;
public $expression = null;
public function getSql(DoctrineORMQuerySqlWalker $sqlWalker)
{
return 'GROUP_CONCAT(' .
($this->isDistinct ? 'DISTINCT ' : '') .
$this->expression->dispatch($sqlWalker) .
')';
}
public function parse(DoctrineORMQueryParser $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);
}
}
Then in your query builder (or DQL);
$qb->select('GROUP_CONCAT(category.name)');
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…