[PR #11014] Fix pruning all collections in table for inherited elements. #12763

Open
opened 2026-01-22 16:15:05 +01:00 by admin · 0 comments
Owner

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

State: closed
Merged: No


When we have two collections with inherited types in one entity, in this example it's PetStore containing Cat and Dog

Cat extends Pet
Dog extends Pet
// Cat and dog are stored in same table using entity_discriminator

PetStore
   Cat[] cats
   Dog[] dogs

And we clear one of them using clear(), second gets cleared too, due to DELETE statement without proper filter.

I think it's bug.

There is fix and test for it.

Bypass before this is merged:
Instead of using

collection.clear()
// or
collection = new ArrayCollection(newElements)

load collection, and clear elements manually in your code

foreach(collection as element){
    collection.removeElement(element)
}
foreach(newElements as newElement){
    collection.add(newElement)
}
**Original Pull Request:** https://github.com/doctrine/orm/pull/11014 **State:** closed **Merged:** No --- When we have two collections with inherited types in one entity, in this example it's `PetStore` containing `Cat` and `Dog` ``` Cat extends Pet Dog extends Pet // Cat and dog are stored in same table using entity_discriminator PetStore Cat[] cats Dog[] dogs ``` And we clear one of them using `clear()`, second gets cleared too, due to DELETE statement without proper filter. I think it's bug. There is fix and test for it. _Bypass before this is merged: Instead of using_ ``` collection.clear() // or collection = new ArrayCollection(newElements) ``` _load collection, and clear elements manually in your code_ ``` foreach(collection as element){ collection.removeElement(element) } foreach(newElements as newElement){ collection.add(newElement) }
admin added the pull-request label 2026-01-22 16:15:05 +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#12763