title: double JOIN and GROUP on hasMany associations
body: <p>I have 3 models (tables):</p>
  
  <pre><code>Presentation hasMany PresentationView hasMany SlideView
  </code></pre>
  
  <p>Fields:</p>
  
  <p>Presentation: <code>id, title</code></p>
  
  <p>PresentationView: <code>id, presentation_id</code></p>
  
  <p>SlideView: <code>id, presentation_view_id, duration</code></p>
  
  <p>I need a query to get statistics for each presentation. Statistics are:</p>
  
  <ol>
  <li>number of PresentationView per each Presentation</li>
  <li>total duration of all SlideView.duration from slide views that belong to Presentation (through PresentationView)</li>
  </ol>
  
  <p>So basically it seems like double JOIN and double GROUP but the joins doesn't work for me - I tried every combination of LEFT/INNER/RIGHT double joins and I can't make it work. The best I had it was that Presentation had grouped PresentationView but duration was SUMed just from SlideViews that belonged to just one PresentationViews not all for Presentation...</p>
  
  <p>I would like to avoid nested SELECTs if possible. just JOIN/GROUP</p>