TYPO3 Extbase how to empty ObjectStorage

此生再无相见时 提交于 2019-12-02 07:36:55

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...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!