Skip to content

Loading…

DDC-2764: An orderBy on Criteria leads to DQL semantical error #3510

Closed
doctrinebot opened this Issue · 6 comments

2 participants

@doctrinebot

Jira issue originally created by user sandermarechal:

Example code:

$criteria = Criteria::create();
$criteria->orderBy(array('field' => Criteria::DESC));

$qb = $em->getRepository('Entity')->createQueryBuilder('e');
$qb->addCriteria($criteria);

$qb->getQuery()->getResult();

That gives:

[Semantical Error] line 0, col 53 near 'field DESC': Error: 'field' is not defined.

@doctrinebot

Comment created by @ocramius:

What is the generated DQL? And is it valid?

@doctrinebot

Comment created by sandermarechal:

The generated DQL comes out as "SELECT e FROM Entity e ORDER BY field DESC". I think it's missing the entity alias in the order by clause.

@doctrinebot

Comment created by sandermarechal:

If you want I can create a Pull Request with a failing test case for this. I just have no idea how I should go about fixing this bug.

@doctrinebot

Comment created by stof:

the alias should be prepended to the field before adding the sort in https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/QueryBuilder.php#L1101

@doctrinebot

Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.4.2 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.