title: Symfony2/Doctrine joined query
body: <p>I need to create a simple query that produces a result set of a database entry plus the username of the person that posted it.</p>
  
  <p>I've tried to setup the associations properly but I'm not sure if that's right either.  I'm finding the whole idea of using these small string identifiers quite confusing.  Surely there must be a simpler way of doing a join?</p>
  
  <p>My two entities:</p>
  
  <pre><code>class Users
  {
    // ...
  
    /**
      * @ORM\Column(type="string")
      * @ORM\OneToMany(targetEntity="Titles", mappedBy="addedBy")
      */
      protected $username;
  
     // ..
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>class Titles
  {
      // ....
  
      /**
        * @ORM\Column(type="string")
        * @ORM\ManyToOne(targetEntity="Users", inversedBy="username")
       */
       protected $addedBy;
  
      // ....
  }
  </code></pre>
  
  <p>with the following in the controller:</p>
  
  <pre><code>$titles = $em-&gt;createQueryBuilder()
               -&gt;select('t.*', 'u.*')
               -&gt;from('dvdLoggerdvdBundle:Titles', 't')
               -&gt;leftJoin('t.addedBy', 'u')
               -&gt;addOrderBy('t.title', 'DESC')
               -&gt;getQuery()
               -&gt;getResult();
  </code></pre>
  
  <p>I'm getting the following error:</p>
  
  <pre><code>[Semantical Error] line 0, col 69 near 'u ORDER BY t.title': Error: Class 
  dvdLogger\dvdBundle\Entity\Titles has no association named addedBy `
  </code></pre>
  
  <p><strong>Update 1</strong></p>
  
  <p>I made all the changes suggested by Tom and did lots of reading!</p>
  
  <p>It appears that in order to overcome the lazy loading feature I need to carry out a leftJoin.  I have rewritten my query as follows:</p>
  
  <pre><code>public function getAllTitles()
  {
      // view all records in db
      $titles = $this-&gt;createQueryBuilder('t')
          -&gt;select('t, u')
          -&gt;leftJoin('t.addedBy', 'u')
          -&gt;addOrderBy('t.title', 'DESC');
  
      return $titles-&gt;getQuery()-&gt;getResult();
  
  }
  </code></pre>
  
  <p>I am getting a result set, but the <code>addedBy</code> is returning NULL when I dump the result set.  As far as I'm aware shouldn't this pull the associated field in from the other table?</p>