[TYPO3-mvc] remove object from object storage
Gianluca Strafella
gianluca.strafella at webformat.com
Thu Aug 1 09:05:17 CEST 2013
Hi Federico,
as it is fetched from storage the object $myFavoriteToRemove?
Have you already checked if $myFavoriteToRemove is an instance of "B"
entity ? If "favorites " property is fetched with lazy loading, could
be need load the real instance on it.
Regards,
Gianluca
Il 31/07/2013 17:50, Federico Bernardin ha scritto:
> 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
>
--
Gianluca Strafella
Software Developer
gianluca.strafella at webformat.com
Tel. +39-0427-926.389
WEBFORMAT srl – www.webformat.com
Via S. Francesco d'Assisi, 6 – 20122 MILANO
Corte Europa, 12 - 33097 SPILIMBERGO (PN)
More information about the TYPO3-project-typo3v4mvc
mailing list