My advise is to first check if the association is in order (without using the 
ZF2 Form component).

You can use the console to validate your mappings:
    $ doctrine orm:validate-schema

Then simply try adding/removing TimeTableList-s to/from a User. If that works, 
you can proceed to using the Form component.

PS: I suspect the association part is in order, and you're having trouble with 
the Form component. I don't have any experience with the ZF2 Form component, 
but maybe others here do. I do suggest you post this issue on a ZF2 
mailing-list or forum, as it's more of a ZF2 thing than a Doctrine2 thing ;)

-- 
Jasper N. Brouwer
(@jaspernbrouwer)


On 19 Feb 2014, at 14:22, paul kendal <[email protected]> wrote:

> 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 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: 
> 
> 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.

-- 
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.

Reply via email to