Cascade remove with extra lazy doesn’t trigger PostRemove #5606

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

Originally created by @aumel on GitHub (Jul 18, 2017).

Originally assigned to: @Ocramius on GitHub.

I encounter a problem with extra lazy and postRemove (doctrine/orm v2.5.6)

Here a simple example. When I remove reference from group, the entity reference is removed from database but PostRemove is never called. If I remove the annotation fetch="EXTRA_LAZY", the PostRemove is called.

Is this the normal behavior?
Or maybe, am I doing something wrong?

class Group
{  
    /**
     * @ORM\OneToMany(targetEntity="GroupReference", mappedBy="group", fetch="EXTRA_LAZY", cascade={"all"}, orphanRemoval=true)
     */
    protected $references;
}
class GroupReference
{
    /**
     * @ORM\ManyToOne(targetEntity="Group", inversedBy="references")
     * @ORM\JoinColumn(name="group_id", referencedColumnName="id")
     */
    protected $group;
}
class MyListener
{
    public function postRemove(LifecycleEventArgs $args)
    {
         var_dump('postRemove called');
    }
}
// PostRemove never called except if I remove annotation extra lazy in the group
$group->removeReference($groupReference);
$this->em->flush();
Originally created by @aumel on GitHub (Jul 18, 2017). Originally assigned to: @Ocramius on GitHub. I encounter a problem with extra lazy and postRemove (`doctrine/orm v2.5.6`) Here a simple example. When I remove reference from group, the entity reference is removed from database but PostRemove is never called. If I remove the annotation `fetch="EXTRA_LAZY"`, the PostRemove is called. Is this the normal behavior? Or maybe, am I doing something wrong? ``` class Group { /** * @ORM\OneToMany(targetEntity="GroupReference", mappedBy="group", fetch="EXTRA_LAZY", cascade={"all"}, orphanRemoval=true) */ protected $references; } ``` ``` class GroupReference { /** * @ORM\ManyToOne(targetEntity="Group", inversedBy="references") * @ORM\JoinColumn(name="group_id", referencedColumnName="id") */ protected $group; } ``` ``` class MyListener { public function postRemove(LifecycleEventArgs $args) { var_dump('postRemove called'); } } ``` ``` // PostRemove never called except if I remove annotation extra lazy in the group $group->removeReference($groupReference); $this->em->flush(); ```
admin added the BugCan't FixQuestion labels 2026-01-22 15:12:32 +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#5606