Project

General

Profile

Actions

Bug #81690

closed

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

Added by Dieter Porth over 7 years ago. Updated over 4 years ago.

Status:
Rejected
Priority:
Should have
Assignee:
-
Category:
Extbase
Target version:
-
Start date:
2017-06-23
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
8
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

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

Actions

Also available in: Atom PDF