Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2422

HIDDEN fileds doesn't work in subqueries

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: 2.3.3
    • Fix Version/s: None
    • Component/s: DQL
    • Security Level: All
    • Labels:
      None

      Description

      I trying to execute query with subquery, which contains GROUP BY:

      $subqueryBuilder = $repository->createQueryBuilder('l2')
          ->select('l2.id, DATE(l2.created) AS HIDDEN created_date')
          ->groupBy('created_date');
      
      $qb = $repository->createQueryBuilder('l');
      $qb->andWhere($qb->expr()->in('l.id', $subqueryBuilder->getDQL()));
      $result = $qb->getQuery()->getArrayResult();
      

      And got error:

      [Syntax Error] line 0, col 80: Error: Expected Doctrine\ORM\Query\Lexer::T_FROM, got ','
      

      If I group simply by "l2.created" without adding it to selected fields, all works fine. But I must use "DATE(l2.created) AS HIDDEN created_date" in selected statement to specify it in GROUP BY statement.

        Activity

        Hide
        Marco Pivetta added a comment -

        You cannot right now.

        That's not supported by all vendors - if you need such a query, use native SQL instead.

        Show
        Marco Pivetta added a comment - You cannot right now. That's not supported by all vendors - if you need such a query, use native SQL instead.
        Hide
        yetanotherape added a comment -

        Ok, so how I can do:

        SELECT
            f.bar
        FROM
            foo f
        WHERE
            f.id IN(
                SELECT
                    b.id
                FROM
                    bar b
                GROUP BY DATE(b.created)
            )
        

        in DQL?

        Show
        yetanotherape added a comment - Ok, so how I can do: SELECT f.bar FROM foo f WHERE f.id IN( SELECT b.id FROM bar b GROUP BY DATE(b.created) ) in DQL?
        Hide
        Marco Pivetta added a comment -

        `HIDDEN` is expected to be used only to handle hydration. Your example is already invalid at SQL level, where it would result in something like:

        SELECT
            f.bar
        FROM
            foo f
        WHERE
            f.id IN(
                SELECT
                    b.baz,
                    b.tab
                FROM
                    bar b
            )
        

        That will obviously fail

        Show
        Marco Pivetta added a comment - `HIDDEN` is expected to be used only to handle hydration. Your example is already invalid at SQL level, where it would result in something like: SELECT f.bar FROM foo f WHERE f.id IN( SELECT b.baz, b.tab FROM bar b ) That will obviously fail

          People

          • Assignee:
            Marco Pivetta
            Reporter:
            yetanotherape
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: