Lifecycle Event "postRemove" suddenly contains lot of unexpected children (OneToMany relation) #5289

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

Originally created by @aight8 on GitHub (Oct 8, 2016).

Info

name     : doctrine/orm
versions : * dev-master, 2.6.x-dev

Reproduction

I have a schema which contains the following:

    /**
     * @ORM\ManyToOne(targetEntity="EntityAbc", inversedBy="children", cascade={"persist","remove"})
     * @ORM\JoinColumn(name="base", referencedColumnName="id", onDelete="SET NULL")
     **/
    private $base;

    /**
     * @ORM\OneToMany(targetEntity="EntityAbc", mappedBy="base")
     **/
    private $children;
  1. I create a new EntityAbc. The children property is an empty collection now. For testing reasons I fetch the entity again from the repository, the children property is still empty as expected.
  2. In the postUpdate/postPersist event the children property is also an empty collection as expected.
  3. But when I delete the entity and the postRemove event is called, the children property contains a Doctrine\ORM\PersistentCollection which contains every EntityABC which is present in the whole table except the current one - so the children property contains now 199 entities when my EntityABC table have totally 200 entities

I use symfonys VarDumper to output the entity in the postRemove event.

Originally created by @aight8 on GitHub (Oct 8, 2016). ## Info ``` name : doctrine/orm versions : * dev-master, 2.6.x-dev ``` --- ## Reproduction I have a schema which contains the following: ``` PHP /** * @ORM\ManyToOne(targetEntity="EntityAbc", inversedBy="children", cascade={"persist","remove"}) * @ORM\JoinColumn(name="base", referencedColumnName="id", onDelete="SET NULL") **/ private $base; /** * @ORM\OneToMany(targetEntity="EntityAbc", mappedBy="base") **/ private $children; ``` 1. I create a new **EntityAbc**. The **children property** is an empty collection now. For testing reasons I fetch the entity again from the repository, the children property is still empty as expected. 2. In the postUpdate/postPersist event the children property is also an empty collection as expected. 3. But when I delete the entity and the **postRemove** event is called, the children property contains a **Doctrine\ORM\PersistentCollection** which contains **every EntityABC** which is present in the whole table except the current one - so the children property contains now 199 entities when my EntityABC table have totally 200 entities I use symfonys VarDumper to output the entity in the postRemove event.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5289