Issue Bug Rejected

#81690ForEach-loop won'tr remove all mn-relation, if I interated the objectstorage only one time

Dieter Porth 06/23/17, 14:28 updated 04/16/20, 20:59

Description

I will remove some selected entry in a mm-relation-table. I need it in a frontend-editing-situation.

If i want to delete all mn-relation entry, I have to use the loop twice, because the first loop won’t delete the last relation.
I use the annotation ‘@cascade remove’ in the myCompany-Modell for the field ‘benefits’.

           
           for ($doubleCountBecauseOfBugInTYPO3Extbase = 1; $doubleCountBecauseOfBugInTYPO3Extbase<3; $doubleCountBecauseOfBugInTYPO3Extbase++) {
                $myBenefits = $myCompany->getBenefits();
                /** @var Benefit $myBenefit */
                foreach ($myBenefits as $myBenefit) {
                    $key = $myBenefit->getUid();
                    if (false === array_search($key, $benefits) || ($countBenefits <= 0)) {
                        $myCompany->removeBenefit($myBenefit);
                        $objects['persistenceManager']->persistAll();
                        $change = true;
                    } else {
                        $check[] = $key;
                    }
                }
                $myCompany->setBenefits($myBenefits);
                $objects['persistenceManager']->persistAll();
            }

Dieter

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.