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 almost 7 years ago. Updated almost 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 #1

Updated by Christian Eßl about 4 years ago

  • Category set to Extbase
Actions #2

Updated by Stefan Froemken almost 4 years ago

Hello Dieter,

please do it that way:

$myCompany->getBenefits()->removeAll(clone $myCompany->getBenefits());
Actions #3

Updated by Alexander Schnitzler almost 4 years ago

  • Status changed from New to Rejected

I consider this solved with Stefan's way of dealing with this.

Actions

Also available in: Atom PDF