DDC-340: DQL Keywords as Model Properties #421

Closed
opened 2026-01-22 12:37:45 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Feb 15, 2010).

Jira issue originally created by user mridgway:

I noticed in doing some work with models and DQL that I wasn't able to use the word 'group' as a model property and do an inner join on it.

Example:

/****
 * @Entity
 */
class User
{
    /****
     * @Id @Column(name="id", type="integer")
     * @GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /****
     * @ManyToOne(targetEntity="Group")
     * @JoinColumn(name="grp", referencedColumnName="id", nullable="false")
     */
    protected $group;
}

/****
 * @Entity
 */
class Group
{
    /****
     * @Id @Column(name="id", type="integer")
     * @GeneratedValue(strategy="AUTO")
     */
    protected $id;

}

Now some DQL:

$qb = $em->createQueryBuilder('User', 'u');
$qb->innerJoin('u.group' , 'ug')
   ->where('ug.sysname = :group_id')
   ->setParameter('group*id', $group*id);

The parser throws a syntax error Error: Expected Doctrine\ORM\Query\Lexer::T_IDENTIFIER, got 'group'

Is there a way to escape identifiers in DQL? Or better yet can we make it not require escaping?

Originally created by @doctrinebot on GitHub (Feb 15, 2010). Jira issue originally created by user mridgway: I noticed in doing some work with models and DQL that I wasn't able to use the word 'group' as a model property and do an inner join on it. Example: ``` /**** * @Entity */ class User { /**** * @Id @Column(name="id", type="integer") * @GeneratedValue(strategy="AUTO") */ protected $id; /**** * @ManyToOne(targetEntity="Group") * @JoinColumn(name="grp", referencedColumnName="id", nullable="false") */ protected $group; } /**** * @Entity */ class Group { /**** * @Id @Column(name="id", type="integer") * @GeneratedValue(strategy="AUTO") */ protected $id; } ``` Now some DQL: ``` $qb = $em->createQueryBuilder('User', 'u'); $qb->innerJoin('u.group' , 'ug') ->where('ug.sysname = :group_id') ->setParameter('group*id', $group*id); ``` The parser throws a syntax error `Error: Expected Doctrine\ORM\Query\Lexer::T_IDENTIFIER, got 'group'` Is there a way to escape identifiers in DQL? Or better yet can we make it not require escaping?
admin added the Bug label 2026-01-22 12:37:45 +01:00
admin closed this issue 2026-01-22 12:37:46 +01:00
Author
Owner

@doctrinebot commented on GitHub (Feb 15, 2010):

Comment created by romanb:

This should be fixed in Parser#JoinAssociationPathExpression where match(T_IDENTIFIER) is used. Instead we should simply match the next token, whatever it is. If we want to be a bit more strict we can do a ctype_alnum check or similar.

@doctrinebot commented on GitHub (Feb 15, 2010): Comment created by romanb: This should be fixed in Parser#JoinAssociationPathExpression where match(T_IDENTIFIER) is used. Instead we should simply match the next token, whatever it is. If we want to be a bit more strict we can do a ctype_alnum check or similar.
Author
Owner

@doctrinebot commented on GitHub (Feb 20, 2010):

Comment created by romanb:

Fixed in trunk.

@doctrinebot commented on GitHub (Feb 20, 2010): Comment created by romanb: Fixed in trunk.
Author
Owner

@doctrinebot commented on GitHub (Feb 20, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Feb 20, 2010): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#421