Tengo el siguiente código, que se basa en la API QueryBuilder de Doctrine para generar sentencias DQL.Problemas Doctrine QueryBuilder y concat
class PlayerRepository extends EntityRepository
{
public function findByPartialNameMatch($trainer, $fullName)
{
$qb = $this->createQueryBuilder('tp');
$qb->innerJoin('tp.player', 'p')
->where($qb->expr()->andX(
$qb->expr()->orX(
$qb->expr()->like(
$qb->expr()->concat('p.firstName', $qb->expr()->concat(' ', 'p.lastName')),
$qb->expr()->literal($fullName.'%')
),
$qb->expr()->like(
$qb->expr()->concat('p.lastName', $qb->expr()->concat(' ', 'p.firstName')),
$qb->expr()->literal($fullName.'%')
)
),
$qb->expr()->eq('tp.trainer', '?1')
)
)
->groupBy('p.id')
->orderBy('p.lastName', 'ASC')
->orderBy('p.firstName', 'ASC')
->setParameter(1, $trainer);
return $qb->getQuery()->getResult();
}
}
Cuando lo ejecuto, Symfony2 lanza el siguiente mensaje de error:
[Syntax Error] line 0, col 123: Error: Expected StateFieldPathExpression | string | InputParameter | FunctionsReturningStrings | AggregateExpression, got ','
Una mirada a la traza de la pila, revela lo siguiente:
at QueryException ::syntaxError ('line 0, col 123: Error: Expected StateFieldPathExpression | string | InputParameter | FunctionsReturningStrings | AggregateExpression, got ','')
in D:\Work\vendor\doctrine\lib\Doctrine\ORM\Query\Parser.php at line 396 -+
at Parser ->syntaxError ('StateFieldPathExpression | string | InputParameter | FunctionsReturningStrings | AggregateExpression')
in D:\Work\vendor\doctrine\lib\Doctrine\ORM\Query\Parser.php at line 2391 -+
at Parser ->StringPrimary()
in D:\Work\vendor\doctrine\lib\Doctrine\ORM\Query\AST\Functions\ConcatFunction.php at line 60 -+
at ConcatFunction ->parse (object(Parser))
in D:\Work\vendor\doctrine\lib\Doctrine\ORM\Query\Parser.php at line 2852 -
De lo anterior, entiendo que el problema está de alguna manera relacionado con la función de ayuda concat, y que la función expec ts la entrada enumerada pero de alguna manera (?) recibió una coma (,).
¿Qué problema hay con el código anterior? Las horas de búsqueda no pudieron arrojar luz sobre el problema.
¡Gracias por toda su ayuda!
De hecho funcionó. La [Doctrine documentation] (http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/query-builder.html#the-expr-class), que proporciona un ejemplo sobre esto, es inexacto. –