title: Symfony query database using foreign key
body: <p>I'm using Symfony 5 and have a question about retrieving from the database using a foreign key.</p>
  <p>I have a User entity and an AdditionalInfo entity, which has a 1:1 relationship with User, although actually not all users will have AdditionalInfo. On the AdditionalInfo entity there is a user field:</p>
  <pre><code>/**
   * @ORM\OneToOne(targetEntity=User::class, inversedBy=&quot;AddInfo&quot;, cascade={&quot;persist&quot;, &quot;remove&quot;})
   * @ORM\JoinColumn(nullable=false)
   */
  private $user;
  </code></pre>
  <p>In the database it has stored this as
  In my controller I have the current user and am trying to access the AdditionalInfo entry for this user by:</p>
  <pre><code>    $user = $this-&gt;getUser();
      $userId = $user-&gt;getId();
      
      $aI= new AdditionalInfo();
      
      $aI= $this-&gt;getDoctrine()
      -&gt;getRepository(AdditionalInfo::class)
      -&gt;findOneBy(['user' =&gt; '$userId']);    
  </code></pre>
  <p>This gets the correct user ID but is returning null. It's also null if I try -&gt;findOneBy(['user' =&gt; '$user'])</p>
  <p>I would be very grateful for any suggestions. I'm wondering if I need to start trying to alter the repository...</p>