Skip to content

Loading…

DDC-2422: HIDDEN fileds doesn't work in subqueries #3136

Closed
doctrinebot opened this Issue · 4 comments

2 participants

@doctrinebot

Jira issue originally created by user yetanotherape:

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.

@doctrinebot

Comment created by @ocramius:

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

@doctrinebot

Issue was closed with resolution "Invalid"

@doctrinebot

Comment created by yetanotherape:

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?

@doctrinebot

Comment created by @ocramius:

You cannot right now.

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

@Ocramius Ocramius was assigned by doctrinebot
@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.