[DDC-2422] HIDDEN fileds doesn't work in subqueries Created: 29/Apr/13  Updated: 01/May/13  Resolved: 01/May/13

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: DQL
Affects Version/s: 2.3.3
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: yetanotherape Assignee: Marco Pivetta
Resolution: Invalid Votes: 0
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.



 Comments   
Comment by Marco Pivetta [ 01/May/13 ]

`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

Comment by yetanotherape [ 01/May/13 ]

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?

Comment by Marco Pivetta [ 01/May/13 ]

You cannot right now.

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

Generated at Wed Jul 30 21:37:27 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.