Hi everyone i have been struggling for 3 months to find a solution to this problem (alas, i cannot find any online documentation or examples to help me to draft the form when my classes are in a ManyToMany relationship)
i followed the tutorial here<https://github.com/bakura10/DoctrineModule/blob/a76195401d8f9fbc2c32e4435edf889793a1d6c8/docs/hydrator.md#the-ultimate-example->which is a great tutorial on using *doctrine 2 Hydrators*. it however does not go into ManyToMany relationships my sample code is on github and can be viewd here: <https://gist.github.com/anonymous/9090879> it may help if i briefly summarize what i tried to do and the results obtained; *summary of my classes; * two basic classes; *the user* and *the Timetable*. a users provide a list of per-specified times when they will be available. i.e 8amt, 9pm shift etc(*the list of specified times is held in the TimeTable class*). the two table are therefore in a *ManyToMany relationship* with each other as *many users* might be available for the* 8am shift* etc( i hope this is correct; please let me know if its not) You will note from my form on the controller that once the form passed validation i had to manually insert the values into the tables; this is obviously incorrect. but i was not able to use the hydrator; i therefore had to do the following: if ($form->isValid()) { $entity = $form->getData(); $user = $this->getEntityManager()->find('BaseDoctrineORM\Entity\User', $this->getUserId()); foreach ($entity->getTimeTable() as $timeTableIds) { $timeTableId = $this->getEntityManager()->find('FormDependencies\Entity\TimeTableList', $timeTableIds); $user->addTimeTable()->add($timeTableId); } $this->getEntityManager()->flush(); return $this->redirect()->toRoute('worker'); } i suspect that the problem comes from which element is the owneing side; i did try to create an instance of the user and bind it to the form; ie: public function availabilityTimesAction() { $form = $this->getTimeTableForm(); $user = $this->getEntityManager()->find('BaseDoctrineORM\Entity\User', 6); $form->bind($user); if ($this->request->isPost()) { $form->setData($this->request->getPost()); ; if ($form->isValid()) { $entity = $form->getData(); $this->getEntityManager()->flush(); } } return array('form' => $form); } i received the following error: Catchable fatal error: Argument 1 passed to BaseDoctrineORM\Entity\User::setTimeTable() must be an instance of FormDependencies\Entity\TimeTableList, array given, i would really really appreciate any advice, example or comments on how to do this correctly warm regards Paul -- You received this message because you are subscribed to the Google Groups "doctrine-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/doctrine-user. For more options, visit https://groups.google.com/groups/opt_out.
