Using Doctrine 2.
I have an entity called 'size' and I'm trying to form some DQL (using the QueryBuilder) to pull these entities from the database.
It looks like 'Size' is a reserved word http://www.doctrine-project.org/docs/orm/2.0/en/reference/dql-doctrine-query-language.html#id3
I'm unable to find a way to escape the entity name (I've tried backticks and double quotes)
$dql = "SELECT product p join p.size size";
Executing the above results in:
Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException' with message '[Syntax Error] line 0, col 53: Error: Expected IdentificationVariable | StateFieldPathExpression | AggregateExpression | "(" Subselect ")" | ScalarExpression, got 'si开发者_运维知识库ze''
It looks like where the manual talks about escaping reserved words - it is referring to column and table names. Can anyone shed any light on this? Is it impossible to used reserved (in DQL) words as entity names?
Thanks
Using an alias I was able to overcome this problem.
$dql = "SELECT p, sizealias FROM Product p JOIN p.size sizealias";
I am not using straight DQL, but using the queryBuilder instead, the above solution works there too.
$qb->select('p, sizealias')
->from('Product', 'p')
->join('p.size', 'sizealias');
精彩评论