title: Doctrine2 many-to-one association won't use JOIN query
body: <p>I have a <code>Car</code> entity with a many-to-one relationship with an entity <code>Owner</code>. If I select all cars, Doctrine does one query on the <code>Car</code> table, and subsequently one query on the <code>Owner</code> table <em>for each car</em>. So fetching N cars becomes N+1 queries instead of a single JOIN query between the <code>Car</code> and <code>Owner</code> tables.</p>
  
  <p>My entities are as follows:</p>
  
  <pre><code>/** @Entity */
  class Car {
  
    /** @Id @Column(type="smallint") */
    private $id;
  
    /** @ManyToOne(targetEntity="Owner", fetch="EAGER")
        @JoinColumn(name="owner", referencedColumnName="id") */
    private $owner;
  
    public function getId()    { return $this-&gt;id; }
    public function getOwner() { return $this-&gt;owner; }
  }
  
  /** @Entity */
  class Owner {
  
    /** @Id @Column(type="smallint") */
    private $id;
  
    /** @Column(type="string") */
    private $name;
  
    public function getName() { return $this-&gt;name; }
  }
  </code></pre>
  
  <p>If I want to list the cars with their owners, I do:</p>
  
  <pre><code>$repo = $em-&gt;getRepository('Car');
  $cars = $repo-&gt;findAll();
  
  foreach($cars as $car) 
    echo 'Car no. ' . $car-&gt;getId() . 
         ' owned by ' . $car-&gt;getOwner()-&gt;getName() . '\n';
  </code></pre>
  
  <p>Now this all works very well, apart from the fact that Doctrine issues a query for each car.</p>
  
  <pre><code>SELECT * FROM Car;
  SELECT * FROM Owner WHERE id = 1;
  SELECT * FROM Owner WHERE id = 2;
  SELECT * FROM Owner WHERE id = 3;
  ....
  </code></pre>
  
  <p>Of course I'd want my query log to look like this:</p>
  
  <pre><code>SELECT * FROM Car JOIN Owner ON Car.owner = Owner.id;
  </code></pre>
  
  <p>Whether I have <code>fetch="EAGER"</code> or <code>fetch="LAZY"</code> doesn't matter, and even if I make a custom DQL query with JOIN between the two entities, <code>$car-&gt;getOwner()</code> still causes Doctrine to query the database (unless I use EAGER, in which case <code>$repo-&gt;findAll()</code> causes all of them).</p>
  
  <p>Am I just too tired here, and this is the way it is supposed to work - or is there a clever way to force Doctrine to do the JOIN query instead?</p>