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

Regine Rosewich regine.rosewich at hoellenberg.biz
Mon May 21 10:06:01 CEST 2012


Hi Davide,

sorry form my late answer. 

The way you described your problem, does not offer a logical solution. On
the other hand your example would not work if you didn't have the
user-object available on the ExtJs side of your application. So you should
be able to generate a JSON from ExtJs which contains the user-id together
with the list of hotel-ids for your hotel transaction. If you work with
ExtJs 4.x and have put your ExtJs frontend into an app (with controllers)
that should be no problem at all.

If you then compare the user-hotel-list on the FLOW3
side($user->getHotels()) with the user-hotel-list of ExtJs(JSON), you can
either enhance the list($user->add($hotel), do nothing, or delete items of
the list ($user->remove($hotel)),

Hope it helps,

Regine

> -----Ursprüngliche Nachricht-----
> Von: flow3-general-bounces at lists.typo3.org [mailto:flow3-general-
> bounces at lists.typo3.org] Im Auftrag von Davide CD
> Gesendet: Mittwoch, 16. Mai 2012 21:20
> An: FLOW3 General Discussion
> Betreff: Re: [FLOW3-general] ManyToMany Association ("owningSide",
> "inversedSide")
> 
> 
> 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
> 
> _______________________________________________
> 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