title: Doctrine skips datasets when using joins and offset
body: <p>I'm working with Doctrine 1.2 in Symfony 1.4 on PHP5.3.</p>
  
  <p>I have a database, in which events have multiple start datetimes (1:n) and types (n:m).</p>
  
  <p>For a program, I want a list of start times and event title, which belong to a special type and are not outdated:</p>
  
  <pre><code>$dql = Doctrine_Query::create()
    -&gt;select('ed.start_datetime,e.title')/*edd.*,*/
    -&gt;from('EventDate ed')
    -&gt;leftJoin('ed.Event e')
    -&gt;leftJoin('e.EventTypes et')
    -&gt;leftJoin('e.Domain d')
    -&gt;orderBy('ed.start_datetime, ed.event_id');
    -&gt;where('e.start_datetime &gt;= ? AND e3.id = ?',array('2011-05-27 17:19:41',2))
    -&gt;fetchArray();
  </code></pre>
  
  <p>The schema can be reviewed at <a href="http://pastebin.com/SdjvsaxW" rel="nofollow">pastebin.com/SdjvsaxW</a>.</p>
  
  <p>Now, doctrine makes two statements</p>
  
  <pre><code>SELECT DISTINCT e5.event_id FROM event_date e5 LEFT JOIN event e6 ON e5.event_id = e6.id LEFT JOIN event_event_type e8 ON (e6.id = e8.event_id) LEFT JOIN event_type e7 ON e7.id = e8.event_type_id WHERE (e5.start_datetime &gt;= '2011-05-27 17:19:41' AND e7.id = '2') ORDER BY e5.start_datetime, e5.event_id
  
  SELECT e.event_id AS e__event_id, e.start_datetime AS e__start_datetime, e2.id AS e2__id, e2.title AS e2__title FROM event_date e LEFT JOIN event e2 ON e.event_id = e2.id LEFT JOIN event_event_type e4 ON (e2.id = e4.event_id) LEFT JOIN event_type e3 ON e3.id = e4.event_type_id WHERE e.event_id IN (*all the IDs from the first query*) AND (e.start_datetime &gt;= '2011-05-27 17:19:41' AND e3.id = '2') ORDER BY e.start_datetime, e.event_id
  </code></pre>
  
  <p>The problem starts when I introduce pagination: When I add an offset, it will be added in the first query. Now, as there might be more than one start time for an event, the number of IDs from the first SELECT DISTINCT query may be smaller than the number of dates. Consequently, dates may be skipped. In my case, there are even less than 50 different events, so the second pages displaying event date 51-100 is indeed empty, despite the fact that there are several hundred event dates (due to recurring events).</p>
  
  <p>I think the problem might be solved leaving away the distinct, but I cannot control that.</p>
  
  <p>Anyone any idea?</p>