Uploaded image for project: 'Doctrine 2 - ORM'
  1. Doctrine 2 - ORM
  2. DDC-2764

An orderBy on Criteria leads to DQL semantical error

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.4
    • Fix Version/s: 2.5, 2.4.2
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      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.

        Issue Links

          Activity

          Hide
          ocramius Marco Pivetta added a comment -

          What is the generated DQL? And is it valid?

          Show
          ocramius Marco Pivetta added a comment - What is the generated DQL? And is it valid?
          Hide
          sandermarechal Sander Marechal added a comment - - edited

          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.

          Show
          sandermarechal Sander Marechal added a comment - - edited 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.
          Hide
          sandermarechal Sander Marechal added a comment -

          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.

          Show
          sandermarechal Sander Marechal added a comment - 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.
          Hide
          stof Christophe Coevoet added a comment -

          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

          Show
          stof Christophe Coevoet added a comment - 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

            People

            • Assignee:
              beberlei Benjamin Eberlei
              Reporter:
              sandermarechal Sander Marechal
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: