removeElement method doesn't remove element on EXTRA_LAZY collection #5977

Closed
opened 2026-01-22 15:23:51 +01:00 by admin · 3 comments
Owner

Originally created by @yurybykov on GitHub (May 30, 2018).

Originally assigned to: @Ocramius on GitHub.

Bug Report

| Version | v2.6.1

Current behavior

The element of collection is not removed. If it check collection element's count, it won't change.

How to reproduce

Retrive parent entity from DB. Try to remove element from property (that collection).
$entity->some_collection->removeElement($element).

Expected behavior

removeElement must remove element from collection.

Originally created by @yurybykov on GitHub (May 30, 2018). Originally assigned to: @Ocramius on GitHub. ### Bug Report | Version | v2.6.1 #### Current behavior The element of collection is not removed. If it check collection element's count, it won't change. #### How to reproduce Retrive parent entity from DB. Try to remove element from property (that collection). $entity->some_collection->removeElement($element). #### Expected behavior removeElement must remove element from collection.
admin added the BugMissing Tests labels 2026-01-22 15:23:51 +01:00
admin closed this issue 2026-01-22 15:23:51 +01:00
Author
Owner

@flaushi commented on GitHub (Oct 10, 2018):

I have almost the same problem currently. But for me the removal does work (databasewise), but the postUpdate event is not triggered, see https://github.com/doctrine/doctrine2/issues/7426

@flaushi commented on GitHub (Oct 10, 2018): I have almost the same problem currently. But for me the removal does work (databasewise), but the postUpdate event is not triggered, see https://github.com/doctrine/doctrine2/issues/7426
Author
Owner

@flaushi commented on GitHub (Oct 11, 2018):

BTW, you did call $em->flush() after removing, did you?

@flaushi commented on GitHub (Oct 11, 2018): BTW, you did call `$em->flush()` after removing, did you?
Author
Owner

@Ocramius commented on GitHub (Oct 15, 2018):

Closing here due to missing tests: from what I can see, this is a possible (typical) owning/inverse side misconception.

$entity->some_collection->removeElement($element).

This call only works when combined with Doctrine\ORM\EntityManager#flush() and if the some_collection is the owning side.

See also https://gist.github.com/Ocramius/3121916

@Ocramius commented on GitHub (Oct 15, 2018): Closing here due to missing tests: from what I can see, this is a possible (typical) owning/inverse side misconception. ```php $entity->some_collection->removeElement($element). ``` This call only works when combined with `Doctrine\ORM\EntityManager#flush()` and if the `some_collection` is the owning side. See also https://gist.github.com/Ocramius/3121916
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5977