Actions
Bug #81690
closedForEach-loop won'tr remove all mn-relation, if I interated the objectstorage only one time
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
Updated by Stefan Froemken over 4 years ago
Hello Dieter,
please do it that way:
$myCompany->getBenefits()->removeAll(clone $myCompany->getBenefits());
Updated by Alexander Schnitzler over 4 years ago
- Status changed from New to Rejected
I consider this solved with Stefan's way of dealing with this.
Actions