title: symfony 2 Error:Call to a member function * on a non-object in *
body: <p>I have an entity Users</p>
  
  <pre><code>class Users
  {
    //...
  
  /**
   * @ORM\Column(name="firstName", type="string", length=50, nullable=true)
   */
  private $firstname;
  
  public function getFirstname()
  {
      return $this-&gt;firstname;
  }
  
  /*
  *@ORM\OneToMany(targetEntity='Worksamples', mappedBy='user')
  */
  private $worksample;
  
  public function __constraction()
  {
      $this-&gt;worksample = new ArrayCollection();
  }
  
  public function getWorksample()
  {
      $this-&gt;worksample;
  }
  
  }
  </code></pre>
  
  <p>and another one entity called Worksamples</p>
  
  <pre><code>class Worksamples
  {
   //...
  
  /**
   * @ORM\Column(name="sampleSource", type="string", length=255, nullable=false)
   */
  private $samplesource;
  
  public function getSamplesource()
  {
      return $this-&gt;samplesource;
  }
  
  /**
   * @ORM\Column(name="UserId", type="integer", nullable=false)
   */
  private $userid;   
  
  public function getUserid()
  {
      return $this-&gt;userid;
  }
  
  
  /*
  *@ORM\ManyToOne(targetEntity="Users", inversedBy="worksample")
  *@ORM\JoinColumn(name="UserId", referencedColumnName="id")
  */
  private $user;
  
  public function getUser()
  {
      return $this-&gt;user;
  }
  
  }
  </code></pre>
  
  <p>in my controller i have this action </p>
  
  <pre><code>public function indexAction($id)
  {
      $user = $this-&gt;getDoctrine()
          -&gt;getRepository('AcmeWellcomeBundle:Users')
          -&gt;find($id);
  
      $sample = $user-&gt;getWorksample()-&gt;getSamplesource();
  
      return $this-&gt;render('AcmeWellcomeBundle:Default:index.html.twig', array('sample' =&gt; $sample));
  
  }
  </code></pre>
  
  <p>and I have this error </p>
  
  <blockquote>
    <p>FatalErrorException: Error: Call to a member function getSamplesource() on a non-object in ....</p>
  </blockquote>
  
  <p>it supposed a User has many Worksamples and a Worksample has only one User.</p>
  
  <p>any help?</p>