title: Symfony2 one to one relationship form
body: <p>I need some help to understand what I'm doing wrong, I've tried to search one answer here, but nothing work.</p>
  
  <p>here my problem..  </p>
  
  <p>I have two entities with a one-to-one relationship:</p>
  
  <pre><code>...
  class FarmInfo
  {
      ...
  
      /**
       * @var integer
       *
       * @ORM\Column(name="areaCovered", type="integer", nullable=true)
       */
      private $areaCovered;
  
      /**
       * @var integer
       *
       * @ORM\Column(name="totalIrrigatedArea", type="integer", nullable=true)
       */
      private $totalIrrigatedArea;
  
      /**
       * @var integer
       *
       * @ORM\Column(name="totalStaff", type="integer", nullable=true)
       */
      private $totalStaff;
  
      /**
       * @var DairyInfo
       * @ORM\OneToOne(targetEntity="DairyInfo", mappedBy="farmInfo", cascade={"persist","remove"})
       */
      private $dairyInfo;
  
      ...
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>...
  class DairyInfo
  {
      ...
  
      /**
       * @var FarmInfo
       *
       * @ORM\OneToOne(targetEntity="FarmInfo", inversedBy="dairyInfo", cascade={"persist"})
       * @ORM\JoinColumn(name="farmInfoId", referencedColumnName="id")
       * 
       */
      private $farmInfo;
  
      /**
       * @var integer
       *
       * @ORM\Column(name="peakCowMilked", type="integer", nullable=true)
       */
      private $peakCowMilked;
  
      /**
       * @var integer
       *
       * @ORM\Column(name="cowsMilkedInWinter", type="smallint", nullable=true)
       */
      private $cowsMilkedInWinter;
  
      ...
  }
  </code></pre>
  
  <p>here the formTypes:</p>
  
  <pre><code>class FarmInfoType extends AbstractType
  {
      /**
       * @param FormBuilderInterface $builder
       * @param array $options
       */
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder-&gt;add('areaCovered');
          $builder-&gt;add('totalIrrigatedArea');
          $builder-&gt;add('totalStaff');
  
          $builder-&gt;add('dairyInfo', new DairyInfoType());
      }
  
      /**
       * @param OptionsResolverInterface $resolver
       */
      public function setDefaultOptions(OptionsResolverInterface $resolver)
      {
          $resolver-&gt;setDefaults(array(
              'data_class' =&gt; 'FOO\CoreBundle\Entity\FarmInfo'
          ));
      }
  
      /**
       * @return string
       */
      public function getName()
      {
          return 'foo_corebundle_farminfo';
      }
  }
  
  class DairyInfoType extends AbstractType
  {
      /**
       * @param FormBuilderInterface $builder
       * @param array $options
       */
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder-&gt;add('peakCowMilked');
          $builder-&gt;add('cowsMilkedInWinter');
      }
  
      /**
       * @param OptionsResolverInterface $resolver
       */
      public function setDefaultOptions(OptionsResolverInterface $resolver)
      {
          $resolver-&gt;setDefaults(array(
              'data_class' =&gt; 'FOO\CoreBundle\Entity\DairyInfo'
          ));
      }
  
      /**
       * @return string
       */
      public function getName()
      {
          return 'foo_corebundle_dairyinfo';
      }
  }
  </code></pre>
  
  <p>That create the form for me with the FarmInfo and the DairyInfo in the same form as I want, but when I persist, FarmInfo persist ok and the DairyInfo persist all fields but the farmInfoId is always null:</p>
  
  <pre><code>+---------------+--------------------+------------+
  | peakCowMilked | cowsMilkedInWinter | farmInfoId |
  +---------------+--------------------+------------+
  |            11 |                 11 |       NULL |
  +---------------+--------------------+------------+
  </code></pre>
  
  <p>What do I have to do to symfony get this Id automatically ?</p>
  
  <p>Thank you all for advance.</p>