title: OneToOne Symfomy2&Doctrine
body: <p>I need to save user with his profile fields. I establish relations. User has one Profile, Profile has one User. I add fields to register form. But when I saving object, I get error,
  Undefined index: profile in /var/www/Symfony/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 2714 . Where my mistake, please help me. I am newbie)
  Here is the code:
  namespace Acme\UserBundle\Entity;</p>
  
  <pre><code>use Doctrine\ORM\Mapping as ORM;
  
  /**
   * Profile
   *
   * @ORM\Table(name="acme_profile")
   * @ORM\Entity
   */
  class Profile
  {
      /**
       * @var integer
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
  
      /**
       * @ORM\Column(name="fio", type="string", length=255)
       */
      protected $fio;
  
  
      /**
       * @ORM\Column(name="birthDate", type="date")
       */
      protected $birthDate;
  
      /**
      * @ORM\OneToOne(targetEntity="Acme\UserBundle\Entity\User", cascade={"persist"})
       * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
       */
      protected $user;
  
      /**
       * Get id
       *
       * @return integer 
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      /**
       * @return mixed
       */
      public function getFio()
      {
          return $this-&gt;fio;
      }
  
      /**
       * @param $fio
       * @return $this
       */
      public function setFio($fio)
      {
          $this-&gt;fio = $fio;
  
          return $this;
      }
  
      /**
       * @return mixed
       */
      public function getBirthDate()
      {
          return $this-&gt;birthDate;
      }
  
      /**
       * @param $birthDate
       * @return $this
       */
      public function setBirthDate($birthDate)
      {
          $this-&gt;birthDate = $birthDate;
  
          return $this;
      }
  
      /**
       * @return mixed
       */
      public function getUser()
      {
          return $this-&gt;user;
      }
  
      /**
       * @param User $user
       * @return $this
       */
      public function setUser(User $user = null)
      {
          $this-&gt;user = $user;
  
          return $this;
      }
  
  }
  </code></pre>
  
  <p>
  
  <pre><code>namespace Acme\UserBundle\Entity;
  
  use FOS\UserBundle\Model\User as BaseUser;
  use Doctrine\ORM\Mapping as ORM;
  use Symfony\Component\Validator\Constraints as Assert;
  
  /**
   * @ORM\Entity
   * @ORM\Table(name="acme_user")
   */
  class User extends BaseUser
  {
      /**
       * @ORM\Id
       * @ORM\Column(type="integer")
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      protected $id;
  
      /**
       * @ORM\OneToOne(targetEntity="Acme\UserBundle\Entity\Profile", cascade={"persist"})
       */
      protected $profile;
  
      public function __construct()
      {
          parent::__construct();
      }
  
      public function setProfile(Profile $profile = null)
      {
          $this-&gt;profile = $profile;
  
          return $this;
      }
  
      public function getProfile()
      {
          return $this-&gt;profile;
      }
  }
  </code></pre>
  
  <p>
  
  <pre><code>namespace Acme\UserBundle\Form\Type;
  
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\FormBuilderInterface;
  use Symfony\Component\OptionsResolver\OptionsResolverInterface;
  
  class RegistrationFormType extends AbstractType
  {
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          // add your custom field
          $builder-&gt;add('profile', new ProfileType());
      }
  
      public function getParent()
      {
          return 'fos_user_registration';
      }
  
      public function getName()
      {
          return 'acme_user_registration';
      }
  
      /**
       * @param OptionsResolverInterface $resolver
       */
      public function setDefaultOptions(OptionsResolverInterface $resolver)
      {
          $resolver-&gt;setDefaults(array(
              'data_class' =&gt; 'Acme\UserBundle\Entity\User'
          ));
      }
  }
  </code></pre>