Bug #54046

Task #55953: Repair and streamline ValueObject support

Removal of ValueObjects from a ManyToMany relationship is not possible

Added by Philipp Maier almost 8 years ago. Updated over 6 years ago.

Must have
Start date:
Due date:
% Done:


Estimated time:
PHP Version:
Has patch:


Once value objects have been added to a PersistentCollection they can no longer be removed by Collection::removeElement.
Attached you can find a working example package that demonstrates the bug.

While Collection::add(ValueObject) works, the same ValueObject can no longer be removed with Collection::removeElement. To reproduce this, navigate to the packages index action, click the "Click me!" button to create a test Entity which holds a collection of ValueObjects.

Afterwards, add a new ValueObject by entering a value into the first input field. You will have this ValueObject listed below after the redirect.

To remove the ValueObject again, enter the same value into the second input field. It will not be removed.

Why this behaves like this is beyond me, I'd expect it to be similar to Entities, where this obviously works.


Test.ValueObject.zip (6.35 KB) Test.ValueObject.zip Philipp Maier, 2013-11-28 21:08
Test.ValueObject.zip (6.49 KB) Test.ValueObject.zip Philipp Maier, 2013-11-28 21:30

Updated by Philipp Maier almost 8 years ago

Added some more convenience to the test package. You can now instantly see the value hash of the submitted ValueObject.


Updated by Carsten Bleicker almost 8 years ago

Maybe its a solution to remove them by filter?
Example from my project how to use a filter on a doctrine collection (see @todo inline comment):


    class AbstractProduct{

         * @var \Doctrine\Common\Collections\Collection<\BLEICKER\I18n\Domain\Model\PropertyTranslation>
         * @ORM\ManyToMany(cascade={"persist", "detach", "merge"})
         * @ORM\OrderBy({"propertyName" = "ASC"})
        protected $propertyTranslations;

         * @return void
        public function __construct() {
            $this->propertyTranslations = new \Doctrine\Common\Collections\ArrayCollection();

         * @return PropertyTranslation
         * @return $this
        public function removePropertyTranslation(PropertyTranslation $propertyTranslation) {
            $filter = function (PropertyTranslation $existingTranslation) use ($propertyTranslation) {
                // @todo At this point you could use persistenceManager to check for equal identities
                return ($existingTranslation->getLocale() === $propertyTranslation->getLocale() && $existingTranslation->getPropertyName() === $propertyTranslation->getPropertyName());

            $existingTranslationToRemove = $this->propertyTranslations->filter($filter);

            while ($existingTranslationToRemove->current()) {

            return $this;


Updated by Adrian Föder over 7 years ago

  • Parent task set to #55953

Updated by Bastian Waidelich over 6 years ago

Just a little reminder (for all major candidates for Flow 3.0): Feature Freeze is in 10 days! Let me know if you need any help with this.

Also available in: Atom PDF