title: Saving child record is not working in doctrine
body: <p>I am using Symfony 2 with Doctrine 2. I have 2 entities User and Email. User can have many Emails. Relation is set up like this.</p>
  
  <pre><code>class User
  {
    /**
     * @ORM\OneToMany(targetEntity="UserEmail", mappedBy="user", cascade={"persist"})
     */
     protected $emails;
  }
  
  class UserEmail
  {
    /**
     * @ORM\ManyToOne(targetEntity="User", inversedBy="user_emails")
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
     */
    protected $user;
  }
  </code></pre>
  
  <p>In controller I am doing something like this.</p>
  
  <pre><code>$user = new User();
  $email = new UserEmail();
  $user-&gt;getEmails()-&gt;add($email);
  $user-&gt;setLocked(false)-&gt;setCreatedAt(new \DateTime());
  
  $form = $this-&gt;createForm(new RegisterUser(), $user, array(
      'action' =&gt; $this-&gt;generateUrl('register'),
  ));
  
  $form-&gt;handleRequest($request);
  
  if($request-&gt;getMethod() == 'POST'){
      if ($form-&gt;isValid()) {
          $registration = $form-&gt;getData();
          $em = $this-&gt;getDoctrine()-&gt;getManager();
          $em-&gt;persist($registration);
          $em-&gt;flush();
      }
  }
  </code></pre>
  
  <p>However I am getting error like this.</p>
  
  <pre><code> An exception occurred while executing 'INSERT INTO user_emails (id, user_id, email, is_verified, token, is_primary, data, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)' with params ["2abbe629-264d-471b-a9dd-4a471657e61c", null, "re@re.com", null, null, null, null, null, null]:
  
   SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column "user_id" violates  not-null constraint
   DETAIL: Failing row contains (2abbe629-264d-471b-a9dd-4a471657e61c, null, re@re.com, null, null, null, null, null, null).
   500 Internal Server Error - DBALException
   1 linked Exception:
  
   PDOException
  </code></pre>
  
  <p>Can somebody please help me. I am new to Symfony 2 world.</p>