title: Sort hasMany relation in Yii2
body: <p>I have a simple relation 1:N to get some prices from a single model.</p>
  
  <pre><code>public function getPrices()
      {
          return $this-&gt;hasMany(Prices::className(), ['device_id' =&gt; 'id']);
      }
  </code></pre>
  
  <p>But I need prices objects sorteds by a specific property in this case <code>$value</code></p>
  
  <p>I've seen multiple examples in <code>Yii 1</code> but nothing in <code>Yii 2</code> </p>
  
  <p>Thanks to @vishu i've tried this:</p>
  
  <pre><code>public function getPrices()
  {
      return $this-&gt;hasMany(Prices::className(), ['device_id' =&gt; 'id'])
          -&gt;viaTable(Prices::tableName(), ['device_id' =&gt; 'id'], function ($query) {
  
              $query-&gt;orderBy(['device_price' =&gt; SORT_DESC]);
          });
  
  }
  </code></pre>
  
  <p>But now it returns a empty array.</p>