DDC-3108: Criteria cannot reference a joined tables' fields when used with an ORM QueryBuilder #3857

Closed
opened 2026-01-22 14:29:14 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Apr 30, 2014).

Originally assigned to: @Ocramius on GitHub.

Jira issue originally created by user Ceiu:

This regression was introduced in 2.4.2 with the addition of the "rootAlias" stuff. Basically, the hard-coded addition of the rootAlias + "." prevents any Criteria object from referencing any field that isn't on the first table selected.

Example:
// Assume $repo is a valid EntityRepository and $value is some scalar value.
$qb = $repo->createQueryBuilder('T1')->join('T1.field', 'T2');

$criteria = new Comparison('T2.field2', Comparison::EQ, $value);

$qb->addCriteria($criteria);
$dql = $qb->getDQL();

$dql is now (roughly) equal to:
SELECT T1 FROM T1 JOIN T1.field T2 WHERE T1.T2.field2 =

Evaluating this causes QueryExceptions to be thrown; usually something along the lines of "Expected Doctrine\ORM\Query\Lexer::, got '.'"

There's a similar issue involving ordering by a related field for the same reason.

Originally created by @doctrinebot on GitHub (Apr 30, 2014). Originally assigned to: @Ocramius on GitHub. Jira issue originally created by user Ceiu: This regression was introduced in 2.4.2 with the addition of the "rootAlias" stuff. Basically, the hard-coded addition of the rootAlias + "." prevents any Criteria object from referencing any field that isn't on the first table selected. Example: // Assume $repo is a valid EntityRepository and $value is some scalar value. $qb = $repo->createQueryBuilder('T1')->join('T1.field', 'T2'); $criteria = new Comparison('T2.field2', Comparison::EQ, $value); $qb->addCriteria($criteria); $dql = $qb->getDQL(); $dql is now (roughly) equal to: SELECT T1 FROM <entityclass> T1 JOIN T1.field T2 WHERE T1.T2.field2 = <value> Evaluating this causes QueryExceptions to be thrown; usually something along the lines of "Expected Doctrine\ORM\Query\Lexer::<token>, got '.'" There's a similar issue involving ordering by a related field for the same reason.
admin added the Bug label 2026-01-22 14:29:14 +01:00
admin closed this issue 2026-01-22 14:29:14 +01:00
Author
Owner
@doctrinebot commented on GitHub (Apr 30, 2014): - is referenced by [DDC-3436: [GH-1212] [DDC-3108] Fix regression where join aliases were no longer accessible in Criteria expressions](http://www.doctrine-project.org/jira/browse/DDC-3436)
Author
Owner

@doctrinebot commented on GitHub (Jan 17, 2015):

Comment created by @ocramius:

Fixed in DDC-3436

@doctrinebot commented on GitHub (Jan 17, 2015): Comment created by @ocramius: Fixed in [DDC-3436](http://www.doctrine-project.org/jira/browse/DDC-3436)
Author
Owner

@doctrinebot commented on GitHub (Jan 17, 2015):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Jan 17, 2015): 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#3857