Bug #54046

Task #55953: Repair and streamline ValueObject support

Removal of ValueObjects from a ManyToMany relationship is not possible

Added by Philipp Maier over 1 year ago. Updated 6 months ago.

Status:New Start date:2013-11-28
Priority:Must have Due date:
Assigned To:- % Done:

0%

Category:Persistence
Target version:TYPO3 Flow Base Distribution - 2.1
PHP Version: Complexity:medium
Has patch:No Affected Flow version:Git master

Description

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.4 kB) Philipp Maier, 2013-11-28 21:08

Test.ValueObject.zip (6.5 kB) Philipp Maier, 2013-11-28 21:30

History

#1 Updated by Philipp Maier over 1 year ago

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

#2 Updated by Carsten Bleicker over 1 year 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):

<?php

    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()) {
                $this->propertyTranslations->removeElement($existingTranslationToRemove->current());
                $existingTranslationToRemove->next();
            }

            return $this;
        }
    }

?>

#3 Updated by Adrian Föder over 1 year ago

  • Parent task set to #55953

#4 Updated by Bastian Waidelich 6 months 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