[TYPO3-mvc] remove object from object storage

Federico Bernardin typo3list at bernardin.it
Wed Jul 31 17:50:03 CEST 2013


Hi guys,
I've a strange behavior with remove an object from object Storage.

This is my situation:

Entity A with property (m:n) favorites of type objectStorage<B>. B is another entity.

My Controller fetches object A from repository and fetches from url an entity of type B (called $myFavoriteToRemove). Then I use this $myFavoriteToRemove to remove the correct object from A->favorites. But the favorite isn't removed. So I debug in deep the code and I found that spl_object_hash($myFavoriteToRemove) hash isn't the same as the object in A->favorites with the same uid, so the detach function of objectstorage doesn't work (it doesn't find any object in storage array).

My code is:
A->removeFavorite($myFavoriteToRemove);
But it doesn't work, the problem is that described above.

So my solution is:
foreach (A->getFavorites() as $favorite) {
					if ($favorite->getUid() == $myFavoriteToRemove->getUid()) {
						A->removeFavorite($favorite);
					}
				}

And this works fine, but is it the real best solution?

thanks
Federico


More information about the TYPO3-project-typo3v4mvc mailing list