Concat three or more fields in the doctrine

The Doctrine query designer allows me to concatenate only two fields.

class Expr {
// ...
public function concat($x, $y); // Returns Expr\Func

To combine 3 fields, I use:

$qb->expr()->concat(
    'table.field1',
    $qb->expr()->concat('table.field2', 'table.field3')
);

And SQL will be:

CONCAT('table.field1', CONCAT('table.field2', 'table.field3'))

How to get one concat?

When I try to call directly

new Expr\Func('CONCAT', array('table.field1', 'table.field2', 'table.field3'));

Executing the request gives me an error

[Syntax error] line 0, col 237: Error: expected doctrine \ ORM \ Request \ Lexer :: T_CLOSE_PARENTHESIS, got ','

Dumping DQL:

CONCAT('table.field1', 'table.field2', 'table.field3')

Flushing SQL with $ qb-> getQuery () -> getSQL ():

[Syntax error] line 0, col 237: Error: expected doctrine \ ORM \ Request \ Lexer :: T_CLOSE_PARENTHESIS, got ','

+4
source share
1 answer

CONCAT Doctrine ORM 2.4.0, , , . DQL .

ORM :

php composer.phar require doctrine/orm:~2.4

, () Expr\Func, Expr::concat; :

new Expr\Func('CONCAT', array('table.field1', 'table.field2', 'table.field3'));

UPDATE PR GitHub Expr::concat

+1

Source: https://habr.com/ru/post/1529976/


All Articles