I want to \"empty\" an ObjectStorage when updating a Object:
It\'s TYPO3 4.6 with a Extbase Extension which allows you to show/add/edit/delete datasets in the frontend.
Call the detach
or removeAll
methods to remove certain or all objects of the storage.
/** @var \Tx_Extbase_Persistence_ObjectStorage $organisationPartners */
$organisationPartners = $organisation->getPartner();
foreach ($organisationPartners as $partner) {
$organisationPartners->detach($partner);
}
Thank you @Wolfgang for your message.
I added the following function to my model:
/**
* detach Partner
*
* @param Tx_Toco3Marketingdb_Domain_Model_Partner $partner
* @return void
*/
public function detachPartner($partner) {
$this->partner->detach($partner);
}
In the controller I added:
$persistanceManager = t3lib_div::makeInstance('Tx_Extbase_Persistence_Manager');
$organisation = $this->firmaRepository->findByUid($uid);
$organisationPartners = $organisation->getPartner();
foreach ($organisationPartners as $organisationPartner) {
$organisation->detachPartner($organisationPartner);
}
$persistanceManager->persistAll();
$organisation->setPartner($partner);
It is important to persist before setting the new (empty) value...