title: Form with Symfony 2 and MongoDB
body: <p>I'm using Symfony 2 with MongoDB and I have a little problem with an embed document. In my application, I have a workout with several exercices (such as push up...)</p>
  
  <p>Here is the workout document:</p>
  
  <pre><code>Skurty\Bundle\TestBundle\Document\Workout:
  fields:
      id:
          id:  true
      date:
          type: date
  embedMany:
      exercices:
        targetDocument: Skurty\Bundle\TestBundle\Document\Exercice
  </code></pre>
  
  <p>And the exercice document:</p>
  
  <pre><code>Skurty\Bundle\TestBundle\Document\Exercice:
  fields:
      id:
          id:  true
      name:
          type: string
      reps:
          type: hash
  </code></pre>
  
  <p>For the form, I'm using 2 types:</p>
  
  <pre><code>class WorkoutType extends AbstractType
  {
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder-&gt;add('date', 'date');
          $builder-&gt;add('exercices', 'collection', array(
              'type'         =&gt; new ExerciceType(),
              'allow_add'    =&gt; true,
              'allow_delete' =&gt; true,
              'prototype'    =&gt; true,
              'by_reference' =&gt; false
          ));
      }
  
      /**
       * Set default
       * @param OptionsResolverInterface $resolver
       */
      public function setDefaultOptions(OptionsResolverInterface $resolver)
      {
          $resolver-&gt;setDefaults(array(
              'data_class' =&gt; 'Skurty\Bundle\TestBundle\Document\Workout',
          ));
      }
  
      public function getName()
      {
          return 'workout';
      }
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>class ExerciceType extends AbstractType
  {
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder-&gt;add('name', 'text');
          $builder-&gt;add('reps', 'collection', array('type' =&gt; 'text'));
      }
  
      /**
       * Set default
       * @param OptionsResolverInterface $resolver
       */
      public function setDefaultOptions(OptionsResolverInterface $resolver)
      {
          $resolver-&gt;setDefaults(array(
              'data_class' =&gt; 'Skurty\Bundle\TestBundle\Document\Exercice'
          ));
      }
  
      public function getName()
      {
          return 'exercice';
      }
  }
  </code></pre>
  
  <p>So in the newAction I use:</p>
  
  <pre><code>public function newAction(Request $request)
  {
      $workout = new Workout();
      $workout-&gt;setDate(new \DateTime());
  
      $form = $this-&gt;createForm(new WorkoutType(), $workout);
  
      return $this-&gt;render('SkurtyTestBundle:Workout:new.html.twig', array('form' =&gt; $form-&gt;createView(), 'workout' =&gt; $workout));
  }
  </code></pre>
  
  <p>In the view:</p>
  
  <pre><code>&lt;table&gt;
      {% for exercice in form.exercices %}
          &lt;tr&gt;
              &lt;td&gt;{{ form_widget(exercice) }}&lt;/td&gt;
          &lt;/tr&gt;
      {% endfor %}
  &lt;/table&gt;
  </code></pre>
  
  <p>And in the createAction (when the post is submitted):</p>
  
  <pre><code>public function createAction(Request $request)
  {
      $form = $this-&gt;createForm(new WorkoutType());
  
      $form-&gt;handleRequest($request);
  
      if ($form-&gt;isValid()) {
          $workout = $form-&gt;getData();
  
          // ...
      }
  }
  </code></pre>
  
  <p>The $form->getData() contains:</p>
  
  <pre><code>Skurty\Bundle\TestBundle\Document\Workout Object
  (
      [id:protected] =&gt; 
      [date:protected] =&gt; DateTime Object
          (
              ...
          )
      [exercices:protected] =&gt; Doctrine\Common\Collections\ArrayCollection Object
          (
              [_elements:Doctrine\Common\Collections\ArrayCollection:private] =&gt; Array
                  (
                      [0] =&gt; Skurty\Bundle\TestBundle\Document\Exercice Object
                          (
                              [id:protected] =&gt; 
                              [name:protected] =&gt; ...
                              [reps:protected] =&gt; Array
                                  (
                                  )
                          )
  
                      [1] =&gt; Skurty\Bundle\TestBundle\Document\Exercice Object
                          (
                              [id:protected] =&gt; 
                              [name:protected] =&gt; ...
                              [reps:protected] =&gt; Array
                                  (
                                  )
                          )
                  )
  
          )
  
  )
  </code></pre>
  
  <p>As you can see, the "reps" are empty, even if they are well submitted, here is the $request:</p>
  
  <pre><code>Symfony\Component\HttpFoundation\ParameterBag Object
      (
          [parameters:protected] =&gt; Array
              (
                  [workout] =&gt; Array
                      (
                          [date] =&gt; Array
                              (
                                  ...
                              )
                          [exercices] =&gt; Array
                              (
                                  [0] =&gt; Array
                                      (
                                          [name] =&gt; ...
                                          [reps] =&gt; Array
                                              (
                                                  [0] =&gt; 5
                                                  [1] =&gt; 5
                                                  [2] =&gt; 5
                                              )
  
                                      )
  
                                  [1] =&gt; Array
                                      (
                                          [name] =&gt; ...
                                          [reps] =&gt; Array
                                              (
                                                  [0] =&gt; 5
                                                  [1] =&gt; 5
                                                  [2] =&gt; 5
                                              )
  
                                      )
                              )
                      )
  
              )
  
      )
  </code></pre>
  
  <p>And I also have the error "This form should not contain extra fields." for each exercice.</p>
  
  <p>Where is the problem?</p>
  
  <p>Thank you!</p>