mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Enable prevention of delete queries
#7544
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 @janopae on GitHub (Aug 26, 2025).
Feature Request
What
I'd like to see a way to prevent a QueryBuilder instance to be turned into a delete query builder later on.
Currently, when you call
$queryBuilder->select()on a QueryBuilder and return it, another actory might call->delete()and overwrite thetypeset previously.Why
PostDeleteandPreDeleteevents do not get fired on delete queries. Therefore, depending on your model, delete queries might be a serious theat to your data consistency. While it is pretty common to enforce the rule that only Repository classes may create query builders for certain entities (using theircreateQueryBuildermethod) among a team, it is pretty common for other classes to add additional constraints to the QueryBuilder.Programmers unaware of the details of the model (e. g. the creator of the model themselves in the future) might acidentally create a
deletequery and bypass the safety shield of the Repository and cause serious damage to the data consistency through this.How
One way would be to throw an exception when changing the type of the QueryBuilder after the explicit use of
select. However, this would be a breaking change.Alternatively, we could implement a new method, called something like
onlyAllowSelect, that causes any other action that tries to change the QueryBuilder type to throw an exception.