title: Yii2 Order By Relations
body: <p>I have the following database:</p>
  
  <pre><code>day: id
  task: id
  day_task: day_id, task_id, weight
  </code></pre>
  
  <p>Now I want to fetch all tasks from a specific day ordered by weight.</p>
  
  <pre><code>public function getTasks()
  {
      return $this-&gt;hasMany(Task::className(), ['id' =&gt; 'task_id'])-&gt;viaTable('day_task', ['day_id' =&gt; 'id'], function ($query) {
          $query-&gt;orderBy(['weight' =&gt; SORT_ASC]);
      });
  }
  </code></pre>
  
  <p>Resulting in:</p>
  
  <pre><code>SELECT * FROM `day_task` WHERE `day_id`=2 ORDER BY `weight`
  SELECT * FROM `task` WHERE `id` IN ('2', '1', '3', '4')
  </code></pre>
  
  <p>The problem is that the DBMS returns the rows as they were stored in the table not considering the order of the IN and so I get '1', '2', '3', '4' instead of '2', '1', '3', '4'.</p>
  
  <p>I could not find any solution apart from fetching it manually row by row.</p>