TYPO3 Extbase how to empty ObjectStorage

前端 未结 2 1695
别那么骄傲
别那么骄傲 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:49

    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);
    }
    
    0 讨论(0)
  • 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...

    0 讨论(0)
提交回复
热议问题