mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Limit in DQL subquery #7291
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Guervyl on GitHub (Dec 29, 2023).
Bug Report
Summary
I want to be able to limit a subquery but doctrine is not adding the limit. I know from an issue you said to fall to SQL native but, the problem is I have to deal with ResultSet mapping.
Current behavior
It does not add the limit into the
$categoryQueryDQL.How to reproduce
Use the above DQL code.
Expected behavior
It was supposed to add the Limit to the DQL.
@greg0ire commented on GitHub (Dec 30, 2023):
Not really, no… I mean, I'm sure you expected it, but I don't know why you expected it: as soon as you provide the DQL in one way (first argument of
createQuery), and the limit/offset another way, I don't know why you expectgetDQL()to provide more, orsetMaxResults()to perform some kind of merge. If what you expected was possible, then there would beLIMITandOFFSETkeywords directly in DQL.@Guervyl commented on GitHub (Dec 30, 2023):
@greg0ire commented on GitHub (Dec 30, 2023):
Ok, let me add some emphasis here:
If what you expected was possible, then there would be
LIMITandOFFSETkeywords directly in DQL.I think you're getting a syntax error, because DQL currently has no such keywords.
@Guervyl commented on GitHub (Jan 2, 2024):
Hi there,
Maybe I'm missing a DQL feature, but this DQL
SELECT g FROM App\Entity\FbGroups g LIMIT 1throws[Syntax Error] line 0, col 36: Error: Expected end of string, got 'LIMIT'.Why is this important to have limit? Because I want this query in DQL:
I could use Join but, this is different result:
I want to list all groups. But with no repetitions. So using subquery to limit the query so that I can even
order byis my only choice. And I can't reproduce it using DQL.@greg0ire commented on GitHub (Jan 2, 2024):
Yes. It does. Because, and this is key, that feature does not exist. There is no LIMIT keyword in DQL for now.
@Guervyl commented on GitHub (Jan 3, 2024):
So, My question was about this. It is impossible to set limit in DQL while
limitis a very crucial feature in SQL.@greg0ire commented on GitHub (Jan 3, 2024):
I asked internally, and to me it's not fully clear why: