[TYPO3-mvc] Problems with clearing an ObjectStorage

Zalán Somogyváry zalan at gmx.net
Wed Jun 22 17:13:29 CEST 2011


Hi Sebastian,

Am 22.06.2011 um 17:06 schrieb Sebastian Michaelsen:

> Hi *,
> 
> i'm having a hard time with quite a simple problem. I just missed something basic or misunderstood something..
> 
> 
> I want to empty an Tx_Extbase_Persistence_ObjectStorage, because an object with an n:m property should lose all its relations.
> 
> Why can't I just call removeAll() on an ObjectStorage? The method exists, but it requires another ObjectStorage as an argument (the group of objects to be removed).
> 
> I tried:
> 
> 
> /**
> * @var Tx_Extbase_Persistence_ObjectStorage<Tx_Myext_Domain_Model_Foo> $favorites
> */
> protected $favorites;
> 
> public function removeAllFavorites() {
> 	$this->getFavorites()->removeAll($this->getFavorites());
> }
> 
> But the ObjectStorage ($this->favorites) is not empty afterwards. It clears out almost all objects, except 1. One object is always left and I don't know why.
> 
> Any hints?
> 
> Kind regards and thanks for any help,
> Sebastian
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc


Why don't you replace your ObjectStorage with a new (empty) one?

public function removeAllFavourites(){
	$this->favourites = new Tx_Extbase_Persistence_ObjectStorage()
}

Best regards,
Zalán Somogyváry





More information about the TYPO3-project-typo3v4mvc mailing list