Skip to content

Commit f6e1dd4

Browse files
mpdudeMalteWunsch
andauthored
Better explain limitations of DQL "DELETE" (#9281)
We think the current documentation does not stress these details enough, so that they are easily overlooked. Co-authored-by: Malte Wunsch <[email protected]> Co-authored-by: Malte Wunsch <[email protected]>
1 parent cccb2e2 commit f6e1dd4

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

docs/en/reference/dql-doctrine-query-language.rst

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -670,11 +670,23 @@ The same restrictions apply for the reference of related entities.
670670

671671
.. warning::
672672

673-
DQL DELETE statements are ported directly into a
674-
Database DELETE statement and therefore bypass any events and checks for the
675-
version column if they are not explicitly added to the WHERE clause
676-
of the query. Additionally Deletes of specified entities are *NOT*
677-
cascaded to related entities even if specified in the metadata.
673+
DQL DELETE statements are ported directly into an SQL DELETE statement.
674+
Therefore, some limitations apply:
675+
676+
- Lifecycle events for the affected entities are not executed.
677+
- A cascading ``remove`` operation (as indicated e. g. by ``cascade={"remove"}``
678+
or ``cascade={"all"}`` in the mapping configuration) is not being performed
679+
for associated entities. You can rely on database level cascade operations by
680+
configuring each join column with the ``onDelete`` option.
681+
- Checks for the version column are bypassed if they are not explicitly added
682+
to the WHERE clause of the query.
683+
684+
When you rely on one of these features, one option is to use the
685+
``EntityManager#remove($entity)`` method. This, however, is costly performance-wise:
686+
It means collections and related entities are fetched into memory
687+
(even if they are marked as lazy). Pulling object graphs into memory on cascade
688+
can cause considerable performance overhead, especially when the cascaded collections
689+
are large. Make sure to weigh the benefits and downsides.
678690

679691
Comments in queries
680692
-------------------

0 commit comments

Comments
 (0)