title: fetch records from two tables relating to each other - symfony
body: <p>I have two table in symfony. The images table has a foreign key to the users table. I want to retrieve records where user id is equal to the argument passed. Here is my attempt</p>
  
  <pre><code>private function serializeUsers(Users $usr) {
          return array(
              'username' =&gt; $usr-&gt;getUsername(),
              'email' =&gt; $usr-&gt;getEmail(),
              'id' =&gt; $usr-&gt;getId(),
  //I have tried using getter method to retrieve image value here but I cannot because image is related to users
              );
          }
  </code></pre>
  
  <p>Here is the controller codes</p>
  
  <pre><code>$restresults = $this-&gt;getDoctrine()
                  -&gt;getRepository('xxxBundle:Users')
                      -&gt;findBy(['id' =&gt; $id]);
  
              array_push($data, $this-&gt;serializeUsers($restresult));
  </code></pre>
  
  <p>As you can see from my above attempts, I am unable to retrieve data for the image table having a foreign key to the users table. Is my design wrong or I have not yet figured out the logic or a better way to approach this</p>