[FLOW3-general] ManyToMany Association ("owningSide", "inversedSide")

Davide CD dmichelangeli at hotmail.com
Wed May 16 21:20:02 CEST 2012


Hi Regine, 
thank you very much for your answer. The problem is that from ExtJS I send only the hotels that are assigned to the user. For Example:
Let's say, that the first time I select 2 hotels for user1. From ExtJs I send a JSON with the identities of the two hotels:
{......  hotels: ["idhotel1","idhotel2"] ...} //this is the user object
Now, I change my mind and I decide that ONLY hotel1 should belong to that user. The JSON string thats comes from ExtJS is following:
{......  hotels: ["idhotel1"] ...} //this is the user objectThe problem now, is that first I have to get rid of the hotel2 but how? Should I use the 
array_diff PHP function  in order to know which hotel is no more selected?And second, I can't add hotel1, cause it is still assigned to this user (I get a "Duplicate key error").
Maybe mine is the wrong approach, 'cause on the owningside of the relationship there are no problems at all.
Thanks for a feedback,Davide

> From: regine.rosewich at hoellenberg.biz
> Date: Wed, 16 May 2012 16:51:53 +0200
> To: flow3-general at lists.typo3.org
> Subject: Re: [FLOW3-general] ManyToMany Association ("owningSide",	"inversedSide")
> 
> Hi Davide,
> 
> may be understood your problem wrong, but as far as I can see you only have to remove hotel1 from user 1 by using a remove-Method within the user-controller (user1->removeHotel($hotel1)).
> 
> Regine
> 
> Am 16.05.2012 um 16:05 schrieb Davide CD:
> 
> > 
> > Hi!
> > I have two classes, User and Hotel which are connected with a ManyToMany relationship. These classes are partially described here (only properties and methods that are involved in the relationship).
> > http://pastebin.com/hheDCvdw
> > 
> > I use Extjs with FLOW3. 
> > A Extjs Grid gives the possibility to assign to a hotel many users. Hotel is the Owningside of this relationship. I can add and remove users assigned to a specific hotel with no problems. Everything works fine.
> > The (big, for me) problem is the inverse side of the relation, when I try to assign many hotels to a user. I read in Doctrine Documentation that you MUST also update the owning side of the relationship (how ??). That's why I put that "for cycle" in the user's method "setHotels". Now, lets say that user 1 has no hotels assigned to it:
> > user1 -> -  no hotels assigned to
> > Let's assigned to hotels to the user1, say, hotel1 and hotel2.
> >> From ExtJS, I send an array to a FLOW3 REST Controller with the two identities of hotel1 and hotel2.
> > user1 -> hotel1, hotel2
> > No problem here. Everything works fine. The hotels are correctly assigned to the user.
> > Now, I would like to remove hotel1 in order to have only hotel2 assigned to user1:
> >> From ExtJS, I send an array with the only the identity of hotel2.
> > 
> > user1 -> hotel2
> > And here is the big problem. I don't know how I can do it. I recieve errors like "DUPLICATE KEY Entry for ...." (. 
> > In other words, I don't know how to avoid the duplicate entry. How can I test (should I ??) if an entry still exists in the association table?
> > Or this is the wrong approach?
> > Thank you very much in advance.
> > Davide
> > 
> > 		 	   		  
> > _______________________________________________
> > FLOW3-general mailing list
> > FLOW3-general at lists.typo3.org
> > http://lists.typo3.org/cgi-bin/mailman/listinfo/flow3-general
> 
> _______________________________________________
> FLOW3-general mailing list
> FLOW3-general at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow3-general
 		 	   		  


More information about the FLOW3-general mailing list