mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Ability to alter QueryBuilder before SQL generation and execution (SQLFilter but with DQL) #7542
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 @Cafeine42 on GitHub (Aug 14, 2025).
Feature Request
What
Add a mechanism (such as an event or an extension point) that allows developers to intercept and modify a QueryBuilder before it is transformed into SQL and executed. This would provide a way to apply filters or additional constraints using the QueryBuilder API instead of raw SQL.
Why
Doctrine’s existing SQLFilter feature is useful for simple filters but requires writing raw SQL directly.
For complex filters, such as those involving subqueries, multiple joins, or dynamic conditional logic, writing raw SQL becomes verbose, repetitive, and harder to maintain. Being able to work at the QueryBuilder level would make filters more expressive, reusable, and easier to test while preserving the benefits of Doctrine’s abstraction layer.
How
Introduce a new event (for example, onQueryBuilderReady) or an extension interface that triggers after the QueryBuilder is built but before SQL generation. Listeners could then modify the QueryBuilder using Doctrine’s fluent API:
This would allow implementing complex query modifications without resorting to raw SQL.