mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Join are lost by the queryBuilder when building a Delete Query #7106
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 @VincentLanglet on GitHub (Feb 14, 2023).
Bug Report
Summary
When writing
The query generated is
And the query crash with
Seems like it's not a recent issue https://stackoverflow.com/questions/17301636/doctrine-querybuilder-delete-with-joins
but
Expected behavior
I would expect the query with the LEFT JOIN.
@mpdude commented on GitHub (Feb 14, 2023):
I don't think
DELETE ... LEFT JOIN ...is supported at all, and I also don't see that in https://www.doctrine-project.org/projects/doctrine-orm/en/2.14/reference/dql-doctrine-query-language.html#clauses.Maybe the
QueryBuildershould throw an exception when you construct a query that way.@VincentLanglet commented on GitHub (Feb 14, 2023):
Rather than throwing an exception, it seems better to add support for it because this is valid SQL https://www.mysqltutorial.org/mysql-delete-join/
@mpdude commented on GitHub (Feb 14, 2023):
Are we talking about DQL or SQL?
@VincentLanglet commented on GitHub (Feb 14, 2023):
Why not both ?
Since it's valid SQL, it should be a valid DQL too and therefore valid Querybuilder too.
I don't know the implementation behing but seems doctrine is able to generate valid SQL or DQL for the Select query:
it doesn't seem impossible to do the same if I add
->delete().@mpdude commented on GitHub (Feb 14, 2023):
Maybe a subselect in the where clause can help you to identify the root entities that you’d like to delete?
@VincentLanglet commented on GitHub (Feb 14, 2023):
Sure, but that's not really the point of the issue.
I can solve my issue by writing a query to get the id and then deleting the following ids. I can also write raw SQL.
I just wanted to report the bug about the lost joins with delete querybuilder because I was suprised:
Looking at the getDql methods,
https://github.com/doctrine/orm/blob/2.14.x/lib/Doctrine/ORM/QueryBuilder.php#L1427-L1478
I wonder if the
part couldn't be replaced by the logic used for the Select.
@dmaicher commented on GitHub (Feb 15, 2023):
Related is this issue on dbal.
Not sure what the support for this is on various RDBMS
@moritz-ngo commented on GitHub (Apr 17, 2025):
Are there any plans to support this in the future? Otherwise I suggest closing this issue and document why this won't get implemented.
Many thanks in advance.