Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2764

An orderBy on Criteria leads to DQL semantical error

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major 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.

        Activity

        Hide
        Marco Pivetta added a comment -

        What is the generated DQL? And is it valid?

        Show
        Marco Pivetta added a comment - What is the generated DQL? And is it valid?
        Hide
        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
        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
        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
        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
        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
        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:
            Benjamin Eberlei
            Reporter:
            Sander Marechal
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: