DDC-3839: EventListener not called when clearing a ManyToMany collection by reference #4702

Open
opened 2026-01-22 14:47:58 +01:00 by admin · 4 comments
Owner

Originally created by @doctrinebot on GitHub (Jul 20, 2015).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user jgoncalves:

I have an issue with a ManyToMany relation. I don't know if it is a bug or the normal behaviour but when I clear a ManyToMany relation of an entity with the following code :

$user->getGroups()->clear();

the event listener linked to my entity is not called when I flush the entity manager.

I have updated the test \Doctrine\Tests\ORM\Functional\ManyToManyEventTest in order to reproduce the issue (see file attached).

Originally created by @doctrinebot on GitHub (Jul 20, 2015). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user jgoncalves: I have an issue with a ManyToMany relation. I don't know if it is a bug or the normal behaviour but when I clear a ManyToMany relation of an entity with the following code : ``` $user->getGroups()->clear(); ``` the event listener linked to my entity is not called when I flush the entity manager. I have updated the test \Doctrine\Tests\ORM\Functional\ManyToManyEventTest in order to reproduce the issue (see file attached).
admin added the Bug label 2026-01-22 14:47:58 +01:00
Author
Owner

@doctrinebot commented on GitHub (Sep 1, 2015):

Comment created by jgoncalves:

Hi, any news about that? Is it an issue or a misunderstanding of how it should work?

@doctrinebot commented on GitHub (Sep 1, 2015): Comment created by jgoncalves: Hi, any news about that? Is it an issue or a misunderstanding of how it should work?
Author
Owner

@tmarly commented on GitHub (Aug 27, 2018):

+1, I still have the pb (sf4 / doctrine orm 2.7-dev).

The pb:

  • the function PersistentCollection->clear()
    • calls $this->takeSnapshot()
      • which set $isDirty = false
  • and in UnitOfWork->computeChangeSet()
    • there is this commit: e7a6d87990 that call listener only if isDirty=true

For information, I'm not using directly the function clear(), however I'm using sf forms, and the form listener calls clear()

++

@tmarly commented on GitHub (Aug 27, 2018): +1, I still have the pb (sf4 / doctrine orm 2.7-dev). The pb: - the function PersistentCollection->clear() - calls $this->takeSnapshot() - which set $isDirty = false - and in UnitOfWork->computeChangeSet() - there is this commit: e7a6d8799071fb33da9c2fcadfe68f829809593a that call listener only if isDirty=true For information, I'm not using directly the function clear(), however I'm using sf forms, and [the form listener](https://github.com/symfony/symfony/blob/ff1727e2ee44d966a64379e90c58b5c54dc87140/src/Symfony/Bridge/Doctrine/Form/EventListener/MergeDoctrineCollectionListener.php#L49) calls clear() ++
Author
Owner

@beberlei commented on GitHub (Feb 16, 2020):

Scheduled this for the next bug release, because it sounds really weird. Can't promise it really gets investigated though

@beberlei commented on GitHub (Feb 16, 2020): Scheduled this for the next bug release, because it sounds really weird. Can't promise it really gets investigated though
Author
Owner

@skylord123 commented on GitHub (Dec 5, 2020):

This is a duplicate of #4173

The event doesn't get called because when you clear a PersistentCollection it takes a snapshot which marks the collection as not dirty.

@skylord123 commented on GitHub (Dec 5, 2020): This is a duplicate of #4173 The event doesn't get called because when you clear a PersistentCollection it takes a snapshot which marks the collection as not dirty.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4702