Group conact with json formact in Doctrine

I am using group concat extention in in Doctrine and it is returning the result set as comma separated values,
But I need to get the values as json format like, {uuid:"4a6fc592-83dc-4f9e-ba4d-b9f3b3fad92d",quantity:"50"}, the query I am using as a subquery in querybuilder, I know it is possible in MySql, but is it possible with doctrine querybuilder.

class GroupConcat extends FunctionNode
{
    public $isDistinct = false;
    public $expression;

    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);
    }
}

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *