[TYPO3-mvc] Problems with clearing an ObjectStorage
Claus Due
claus at wildside.dk
Wed Jun 22 17:14:07 CEST 2011
Hi Sebastian,
When you use getFavorites() you de-reference the variable. So, from inside the model:
$this->favorites->removeAll($this->favorites);
... and from outside:
$favorites = $object->getFavorites();
$favorites->removeAll($favorites);
$object->setFavorites($favorites);
// which is the equivalent of $object->setFavorites($this->objectManager->get('Tx_Extbase_Persistence_ObjectStorage');
... or add a method on your Model:
public function removeAllFavorites() {
$this->favorites->removeAll($this->favorites);
}
-----
Venlig hilsen / Kind regards,
Claus Due
Fart Joke Connoisseur
http://fedext.net/
On Jun 22, 2011, at 5:06 PM, Sebastian Michaelsen wrote:
> 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
More information about the TYPO3-project-typo3v4mvc
mailing list