TYPO3 Extbase how to empty ObjectStorage

前端 未结 2 1707
别那么骄傲
别那么骄傲 2021-01-28 02:17

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.

2条回答
  •  旧巷少年郎
    2021-01-28 02:50

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

提交回复
热议问题