title: Symfony 3.0 nested entities not saving
body: <p>So I have an Experiment Entity which has many RNASeq entities. However, when I try to save an Experiment with an RNASeq entry (via the <code>newAction</code>), only the Experiment portion saves. </p>
  
  <p>My controller is as follows:</p>
  
  <pre><code>    &lt;?php
      // src/AppBundle/Controller/ExperimentController.php
      namespace AppBundle\Controller;
  
      use AppBundle\Entity\Experiment;
      use AppBundle\Entity\RNASeq;
      use AppBundle\Form\Type\ExperimentType;
      use Symfony\Bundle\FrameworkBundle\Controller\Controller;
      use Symfony\Component\HttpFoundation\Request;
      use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
      use Symfony\Component\HttpFoundation\Response;
  
      // TODO: deleteAction should be implemented. 
  
      class ExperimentController extends Controller {
          /**
           * @Route("/experiment/index", name="experiment_index")
           */
          public function indexAction() {
              // Grab all experiments from database and hand them to template. 
              $repository = $this-&gt;getDoctrine()-&gt;getRepository('AppBundle:Experiment');
              $experiments = $repository-&gt;findAll();
              return $this-&gt;render('experiment/index.html.twig',['experiments' =&gt; $experiments]);
          }
  
          /**
           * @Route("/experiment/new", name="experiment_new")
           */
          public function newAction(Request $request) {
              $experiment = new Experiment();
  
              $form = $this-&gt;createForm(ExperimentType::class, $experiment);
  
              $form-&gt;handleRequest($request);
  
              // On submission.
              if ($form-&gt;isValid()) {
                  $em = $this-&gt;getDoctrine()-&gt;getManager();
                  $em-&gt;persist($experiment);
                  // For each nested object. 
                  foreach($experiment-&gt;getRNASeqs() as $rnaseq) {
                      $em-&gt;persist($rnaseq);
                  }
                  $em-&gt;flush();
                  return $this-&gt;redirectToRoute('experiment_index');
              }
  
              return $this-&gt;render('experiment/form.html.twig', array('form' =&gt; $form-&gt;createView()));
          }
  
          /**
           * @Route("/experiment/show/{id}", name="experiment_show")
           * TODO: Not sure if nessesary (wasn't in last system).
           */
          public function showAction($id) {
              return $this-&gt;render('experiment/show.html.twig');
          }
  
          /**
           * @Route("/experiment/edit/{id}", name="experiment_edit")
           */
          public function editAction(Request $request, $id) {
              $repository = $this-&gt;getDoctrine()-&gt;getRepository('AppBundle:Experiment');
              $experiment = $repository-&gt;find($id);
  
              $form = $this-&gt;createForm(ExperimentType::class, $experiment);
  
              $form-&gt;handleRequest($request);
  
              return $this-&gt;render('experiment/form.html.twig', array('form' =&gt; $form-&gt;createView()));
          }
  
  }
    ?&gt;
  </code></pre>
  
  <p>I've attempted to follow the <a href="http://symfony.com/doc/current/cookbook/form/form_collections.html" rel="nofollow">Symfony documentation</a>. However, it doesn't specifically go over a One-to-Many example, and I fear this is possibly where I've messed up. </p>
  
  <p>For the sake of brevity my Entity classes and the rest of my code can be found <a href="https://github.com/lutrasdebtra/bioinf_poem/tree/master/src/AppBundle/Entity" rel="nofollow">here</a>.</p>
  
  <p>Edit:</p>
  
  <p>I've noticed that during a creation event, the <code>insert into</code> events don't seem to have the correct relationship attributes:</p>
  
  <pre><code>    INSERT INTO experiment (title, exp_type, sample_nums) VALUES (?, ?, ?)
  Parameters: { 1: fe, 2: RNASeq, 3: 'a:1:{i:0;i:68767;}' }
  
      INSERT INTO rnaseq (quality, ribodepleted, final_quality, sample_num, protocol_used, step1, step1result, service_provider, platform, data_files, pipeline, pipeline_parameters, result_files, experiment_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
  Parameters: { 1: fds, 2: 0, 3: fes, 4: 7876, 5: esf, 6: 0, 7: fsd, 8: fs, 9: fs, 10: fsd, 11: sdf, 12: fds, 13: fsd, 14: null }
  </code></pre>
  
  <p><code>Experiment</code> appears to be missing an update to its <code>rnaSeqs</code> attribute, and <code>RNASeq</code> has a <code>null</code> parameter for <code>experiment_id</code>.</p>