[PR #12068] QueryBuilder: prevent misuse of DELETE with LIMIT #13450

Closed
opened 2026-01-22 16:17:09 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/12068

State: closed
Merged: Yes


Imagine you want to delete just last entry, but all your rows disappear:

$this->entityManager->createQueryBuilder()
            ->delete(MyEntity::class, 'e')
            ->orderBy('e.createdAt', 'ASC')
            ->setMaxResults(1); // limit ignored silently

I believe Doctrine should protect developers from doing destructive operations by not silently omitting crucial part of query builder (LIMIT, although named setMaxResults).

**Original Pull Request:** https://github.com/doctrine/orm/pull/12068 **State:** closed **Merged:** Yes --- Imagine you want to **delete just last entry, but all your rows disappear**: ```php $this->entityManager->createQueryBuilder() ->delete(MyEntity::class, 'e') ->orderBy('e.createdAt', 'ASC') ->setMaxResults(1); // limit ignored silently ``` I believe Doctrine should protect developers from doing destructive operations by not silently omitting crucial part of query builder (`LIMIT`, although named `setMaxResults`).
admin added the pull-request label 2026-01-22 16:17:09 +01:00
admin closed this issue 2026-01-22 16:17:09 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#13450