title: symfony2 query builder in a complex way
body: <p>I need to know the best way to go about doing this...  I have a table in my database, for this post we'll call it TC, it has only a few fields I am interested in:</p>
  
  <p><code>id, daydate, noteBy_id, and totaltime</code></p>
  
  <p>noteBy_id is assigned to the user table, which has again only a few items I am looking for...</p>
  
  <p><code>id, first_name, last_name, user_name, department, parentcompany</code></p>
  
  <p>department is in reference to yet a third table which only has <code>id</code> and <code>departmentName</code> in the fields...</p>
  
  <p>Using the query builder, I've created this so far:</p>
  
  <pre><code>$query = $qb-&gt;select('t', 'u')
  -&gt;leftJoin('t.noteBy', 'u', 'WITH', 'u.id = 't.noteBy')
  -&gt;where('t.daydate BETWEEN :start AND :end')
  -&gt;andWhere('u.parentcompany = :pid')
  -&gt;andWhere('u.department = :dep)
  -&gt;groupBy('u.id')
  -&gt;setParameter('start', $start)
  -&gt;setParameter('end', $end)
  -&gt;setParameter('dep', $department)
  -&gt;getQuery();
  </code></pre>
  
  <p>Now, this query works as is but it returns this:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [id] =&gt; 6
              [in1] =&gt; DateTime Object
                  (
                      [date] =&gt; 2012-04-17 09:10:00
                      [timezone_type] =&gt; 3
                      [timezone] =&gt; America/Denver
                  )
  
              [out1] =&gt; 
              [in2] =&gt; 
              [out2] =&gt; 
              [in3] =&gt; 
              [out3] =&gt; 
              [totaltime] =&gt; 0.00
              [daydate] =&gt; DateTime Object
                  (
                      [date] =&gt; 2012-04-17 09:10:00
                      [timezone_type] =&gt; 3
                      [timezone] =&gt; America/Denver
                  )
  
              [noteBy] =&gt; Array
                  (
                      [username] =&gt; j
                      [usernameCanonical] =&gt; j
                      [email] =&gt; me@me.me
                      [emailCanonical] =&gt; me@me.me
                      [enabled] =&gt; 1
                      [salt] =&gt; 
                      [password] =&gt;     
                      [credentialsExpired] =&gt; 
                      [credentialsExpireAt] =&gt; 
                      [id] =&gt; 124
                      [full_name] =&gt; 
                      [first_name] =&gt; J
                      [last_name] =&gt; B
                      [socialsecurity] =&gt; 
                      [phone] =&gt; 
                      [phone2] =&gt; 
                      [address1] =&gt; 
                      [address2] =&gt; 
                      [city] =&gt; 
                      [state] =&gt; 
                      [zip] =&gt; 
                      [startdate] =&gt; 
                      [notes] =&gt; 
                  )
  
          )
  
  )
  </code></pre>
  
  <p>Which is wrong, because it's only got 1 item where in the query that was run it should have 2 in the database..</p>
  
  <p>How it should look like is:</p>
  
  <pre><code>[0]
    (
    [id] =&gt; '1'
    [first_name] =&gt; 'j'
    [last_name] =&gt; 'b'
    [username] =&gt; 'jb'
    [department] =&gt; 'some department'
    [total_time] =&gt; SUM of all records in TC.total_time for user id 1
  )
  [1]
    (
    [id] =&gt; '2'
    [first_name] =&gt; 'frank'
    [last_name] =&gt; 'blew'
    [username] =&gt; 'fb'
    [department] =&gt; 'some department'
    [total_time] =&gt; SUM of all records in TC.total_time for user id 2
  )
  </code></pre>
  
  <p>But, there should only be entries in the resulting array, if the user id has at least 1 match in the TC table...  Any help on figuring this query out is appreciated..</p>