Orm: BC: Expected Doctrine\ORM\Query\Lexer::T_ALIASED_NAME, got 'Member'

Created on 17 Jun 2018  路  8Comments  路  Source: doctrine/orm

BC Break Report

| Q | A
|------------ | ------
| BC Break | yes
| Version | 2.6.1

Summary

I have an entity Member (with a field id), and determine the maximum id as follows:

<?php
$em->getRepository('Member')
   ->createQueryBuilder()
   ->select('MAX(m.id)')
   ->getQuery()
   ->getSingleScalarResult();

Previous behavior

It used to return the highest id (in 2.5.x).

Current behavior

This throws a QueryException now (in 2.6.1):

[Syntax Error] line 0, col 22: Error: Expected Doctrine\ORM\QueryLexer::T_ALIASED_NAME, got 'Member'

#0 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(452): Doctrine\ORM\Query\QueryException::syntaxError('line 0, col 22:...', Object(Doctrine\ORM\Query\QueryException))
#1 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(309): Doctrine\ORM\Query\Parser->syntaxError('Doctrine\\ORM\\Qu...')
#2 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(967): Doctrine\ORM\Query\Parser->match(100)
#3 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(1726): Doctrine\ORM\Query\Parser->AbstractSchemaName()
#4 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(1578): Doctrine\ORM\Query\Parser->RangeVariableDeclaration()
#5 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(1313): Doctrine\ORM\Query\Parser->IdentificationVariableDeclaration()
#6 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(874): Doctrine\ORM\Query\Parser->FromClause()
#7 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(843): Doctrine\ORM\Query\Parser->SelectStatement()
#8 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(259): Doctrine\ORM\Query\Parser->QueryLanguage()
#9 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(355): Doctrine\ORM\Query\Parser->getAST()
#10 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query.php(283): Doctrine\ORM\Query\Parser->parse()
#11 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query.php(295): Doctrine\ORM\Query->_parse()
#12 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php(957): Doctrine\ORM\Query->_doExecute()
#13 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php(912): Doctrine\ORM\AbstractQuery->executeIgnoreQueryCache(NULL, 4)
#14 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php(793): Doctrine\ORM\AbstractQuery->execute(NULL, 4)
#15 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php(821): Doctrine\ORM\AbstractQuery->getSingleResult(4)
#16 /path/to/app/public/test.php(11): Doctrine\ORM\AbstractQuery->getSingleScalarResult()
#17 {main}

How to reproduce

See code snippet above.

Bug Invalid

All 8 comments

Can you try following instead:

<?php $em->getRepository('Member') ->createQueryBuilder('m') ->select('MAX(m.id)') ->getQuery() ->getSingleScalarResult();

@Warxcell Thanks for your response. I can't spot a difference between your snippet and mine, could you elaborate on that?

@caugner Opps. Sorry, my wrong. I edited my response.

@caugner as pointed out by @Warxcell, the method EntityRepository#createQueryBuilder() requires an argument - which is not provided by your snippet. That argument is mandatory for a very long time.

Can you double check on your code if you're really not providing that argument? That's also supposed to raise a fatal error in PHP 7.1+ (it was a warning before).

@lcobucci I was on PHP 7.1 when I updated from 2.5.1 to 2.6.1, and I'm pretty sure it neither raised a fatal error nor a warning (I have PHP error reporting via email that includes warnings); hence the BC Break Report.

As this issue has served its purpose though, I'm closing it now.

@Warxcell @lcobucci Thank you for explaining the reason for this exception.

@caugner glad it helped :+1:

The fact that nothing was reported is quite disturbing and I'd recommend you to review your configuration - you can check PHP's behaviour here: https://3v4l.org/7rVFR.

I'm having a similar issue.

My code:
$groups = $em->getRepository('Group')
->createQueryBuilder('g')
->where('g.users LIKE :myUserId')
->setParameter('myUserId', '%' . $user->getId() . '%')
->getQuery()
->getResult();


the error i'm getting :

Doctrine\ORM\QueryQueryException: [Syntax Error] line 0, col 14: Error: Expected Doctrine\ORM\QueryLexer::T_ALIASED_NAME, got 'Group'


Tried 3 diferent way of building DQL, always getting same error.

_dql: "SELECT g FROM Group g WHERE g.users LIKE :myUserId"

@Limado Don't use Group. It's reserved word.

Was this page helpful?
0 / 5 - 0 ratings