title: How get sum of field in the related table in one query in Yii2
body: <p>Everyone,
  I have 2 tables, that related via third:
  Structure looks like below:</p>
  
  <pre><code>Playlist: id, channel_id, name, date
  Files: id, name, duration
  Playlist-rel-Files: list_id, file_id
  </code></pre>
  
  <p>I'm using ActiveRecord in my app. When I use such query to get last playlist:</p>
  
  <pre><code>$pl = Playlist::find()
                  -&gt;where(['channel_id' =&gt; $model-&gt;channel_id])
                  -&gt;orderBy(['date' =&gt; SORT_DESC])
                  -&gt;limit(1)
                  -&gt;one();
  </code></pre>
  
  <p>Then I use such code to get all files, that related with last playlist:</p>
  
  <pre><code>$f = $pl-&gt;files;
  </code></pre>
  
  <p>All is OK, and I get Array of files, but I don't need the list of them, I need only SUM of files duration, to get this SUM, I will need to run through array in foreach, my question is:</p>
  
  <p>how can I modify my first query to get Playlist data AND sum of duration of this playlist's files in one query ? is it possible ?</p>