Everyone, I have 2 tables, that related via third: Structure looks like below:
Playlist: id, channel_id, name, date Files: id, name, duration Playlist-rel-Files: list_id, file_id
I'm using ActiveRecord in my app. When I use such query to get last playlist:
$pl = Playlist::find() ->where(['channel_id' => $model->channel_id]) ->orderBy(['date' => SORT_DESC]) ->limit(1) ->one();
Then I use such code to get all files, that related with last playlist:
$f = $pl->files;
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:
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 ?