title: Symfony 2 fetching data using foreign key returns Undefined index
body: <p>I have 3 entities : User , UserRole , UserProfile. 
  My primary key for the userprofile entity is actually a foreign key from user entity which is the UserId.
  <strong>Everytime I try to access userProfile using the foreign key userid. I always got an error of undefined index of userID.</strong></p>
  
  <p>this is the exact error message</p>
  
  <p>**> Notice: Undefined index: userID in</p>
  
  <blockquote>
    <p>C:\wamp\www\SymfonyFolder\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php
    line 2583**</p>
  </blockquote>
  
  <p>Controller
      .....
      ....</p>
  
  <pre><code>public function profileAction($id)
      {
          $user = new User();
          $user_repository = $this-&gt;getDoctrine()-&gt;getRepository('AcmePodUserBundle:User');
          $user = $user_repository-&gt;find($id);
  
          $userprofile = new UserProfile();
          $userprofile_repository = $this-&gt;getDoctrine()-&gt;getRepository('AcmeUserBundle:UserProfile');       
          $userprofile = $userprofile_repository-&gt;find($user);
  
         return new Response($userprofile); // this is not the actual output i need. I just used this simply to test if userprofile has some value. 
  }
  </code></pre>
  
  <p>User.orm.yml</p>
  
  <pre><code>type:  entity
    table: reg_user
    oneToOne:
    id:
      userID:
        column: user_id
        type: integer
        generator: { strategy: AUTO }
        targetEntity: UserProfile
        mappedBy: userProfileID
  </code></pre>
  
  <p>UserProfile.orm.yml</p>
  
  <pre><code>type:  entity
    table: users_profile
    id:
      userProfileID:
        associationKey: true
    fields:
      firstName:
        column: first_name
        type: string
        length: 255
        unique: true
        nullable: false
      lastName:
        column: last_name
        type: string
        length: 255
        nullable: false
   oneToOne:
      userProfileID:
        targetEntity: User
        inversedBy: userID
        joinColumn:
          name: fk_user_id
          referencedColumnName: user_id
  </code></pre>
  
  <p>User.php</p>
  
  <pre><code>class User implements AdvancedUserInterface, \Serializable
  {
  
  // @var auto integer
  protected $userID;
  
  // @var string
  protected $userName;
  
  // @var string
  protected $salt;
  
  // @var string - must not persist to DB
  protected $plainPassword;
  
  // @var string
  protected $password;
  
  // @var string
  protected $email;
  
  // @var boolean
  protected $isActive;
  
  // @var string
  protected $confirmationCode;
  
  // @var datetime
  protected $createdAt;
  
  // @var string - must not persist to DB
  protected $chooseRole;
  
  // @var for roles fk_role_id - mapped
  protected $userRole;
  
  
  /* _construct() is an instant instance of the entity*/
  
  public function __construct()
  {
      date_default_timezone_set('Asia/Manila');
      $this-&gt;createdAt = new \DateTime("now");
  
  //all users are inactive upon registration.
  //isActive turns 'true' with the use of email confirmation
      $this-&gt;isActive = false; 
  }
  
  public function __toString()
  {
      return strval($this-&gt;userID);
  }
  
  /**
   * Get userID
   *
   * @return integer 
   */
  public function getUserID()
  {
      return $this-&gt;userID;
  }
  
  /**
   * Set userName
   *
   * @param string $userName
   * @return User
   */
  public function setUserName($userName)
  {
      $this-&gt;userName = $userName;
  
      return $this;
  }
  
  /**
   * Get userName
   *
   * @return string 
   */
  public function getUserName()
  {
      return $this-&gt;userName;
  }
  
  /**
   * Set salt
   *
   * @param string $salt
   * @return User
   */
  public function setSalt($salt)
  {
      $this-&gt;salt = $salt;
  
      return $this;
  }
  
  /**
   * Get salt
   *
   * @return string 
   */
  public function getSalt()
  {
      return $this-&gt;salt;
  }
  
  
  public function setPlainPassword($plainPassword)
  {
      $this-&gt;plainPassword = $plainPassword;
  
      return $this;
  }
  
  public function getPlainPassword()
  {
      return $this-&gt;plainPassword;
  }
  
  /**
   * Set password
   *
   * @param string $password
   * @return User
   */
  public function setPassword($password)
  {
      $this-&gt;password = $password;
  
      return $this;
  }
  
  /**
   * Get password
   *
   * @return string 
   */
  public function getPassword()
  {
      return $this-&gt;password;
  }
  
  /**
   * Set email
   *
   * @param string $email
   * @return User
   */
  public function setEmail($email)
  {
      $this-&gt;email = $email;
  
      return $this;
  }
  
  /**
   * Get email
   *
   * @return string 
   */
  public function getEmail()
  {
      return $this-&gt;email;
  }
  
  /**
   * Set isActive
   *
   * @param boolean $isActive
   * @return User
   */
  public function setIsActive($isActive)
  {
      $this-&gt;isActive = $isActive;
  
      return $this;
  }
  
  /**
   * Get isActive
   *
   * @return boolean 
   */
  public function getIsActive()
  {
      return $this-&gt;isActive;
  }
  
  /**
   * Set confirmationCode
   *
   * @param string $confirmationCode
   * @return User
   */
  public function setConfirmationCode($confirmationCode)
  {
      $this-&gt;confirmationCode = $confirmationCode;
  
      return $this;
  }
  
  /**
   * Get confirmationCode
   *
   * @return string 
   */
  public function getConfirmationCode()
  {
      return $this-&gt;confirmationCode;
  }
  
  /**
   * Set createdAt
   *
   * @param \DateTime $createdAt
   * @return User
   */
  public function setCreatedAt($createdAt)
  {
      $this-&gt;createdAt = $createdAt;
  
      return $this;
  }
  
  /**
   * Get createdAt
   *
   * @return \DateTime 
   */
  public function getCreatedAt()
  {
      return $this-&gt;createdAt;
  }
  
  public function setChooseRole($chooseRole)
  {
      $this-&gt;chooseRole = $chooseRole;
  
      return $this;
  }
  
  public function getChooseRole()
  {
      return $this-&gt;chooseRole;
  }
  
  /**
   * Set userRole
   *
   * @param CloudPod\UserBundle\Entity\UserRoles $userRole
   * @return User
   */
  public function setUserRole(\CloudPod\UserBundle\Entity\UserRoles $userRole = null)
  {
      $this-&gt;userRole = $userRole;
  
      return $this;
  }
  
  /**
   * Get userRole
   *
   * @return CloudPod\UserBundle\Entity\UserRoles 
   */
  public function getUserRole()
  {
      return $this-&gt;userRole;
  }
  
  
  /**
   * @see \Serializable::serialize()
   */
  public function serialize()
  {
      return serialize(array(
          $this-&gt;userID,
      ));
  }
  
  /**
   * @see \Serializable::unserialize()
   */
  public function unserialize($serialized)
  {
      list (
          $this-&gt;userID,
      ) = unserialize($serialized);
  }
  
  public function isAccountNonExpired()
  { return true; }
  
  public function isAccountNonLocked()
  { return true; }
  
  public function isCredentialsNonExpired()
  { return true; }
  
  public function isEnabled()
  { return $this-&gt;isActive; }
  
     /**
   * @inheritDoc
   */
  public function eraseCredentials()
  {
  }
  
  public function getRoles()
  {
    return array($this-&gt;userRole);  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I think the problem is on my controller codes. Can somebody tell me the proper way of coding it.
  P.S I seperated the user to user profile because i dont want to mix up in a table the user account data(like username, role, etc.) with its user info.</p>