title: How can I limit an associated entity result in Doctrine2?
body: <p>I have the following query:</p>
  
  <pre><code>$query = $this-&gt;getEntityManager()-&gt;createQuery('
                        SELECT u, p, m
                        FROM MyCoreBundle:User u
                        JOIN u.programmes p
                        JOIN u.motivation m
                        ');
  
  $result = $query-&gt;getResult();
  </code></pre>
  
  <p>I want to restrict the motivation objects returned for each user to be the result of this second query which I am using elsewhere (On the Motivation repository):</p>
  
  <pre><code>$query = $this-&gt;getEntityManager()-&gt;createQuery('
                        SELECT m FROM MyCoreBundle:Motivation m
                        WHERE m.user = :user
                        ORDER BY m.date DESC');
  
  $query-&gt;setParameter('user',$user);
  $query-&gt;setFirstResult(0);
  $query-&gt;setMaxResults(1);
  //@TODO if there is not result recorded for the user, return sth which indicates this
  return $query-&gt;getResult();
  </code></pre>
  
  <p>Is there a way to limit and restrict motivation in the first query or a better approach?</p>