title: Order By Field IN Yii2
body: <p>I got this problem and not found any solution with yii instrument. Someone know how to solve this problem ? </p>
  
  <p>Eventually, i used this bad code</p>
  
  <pre><code>$params = [];
  foreach ($recipeIds as $i =&gt; $recipeId) {
      $params[':id_'.$i] = $recipeId;
  }
  
  $recipes = Recipes::findBySql(
          'SELECT
              *
          FROM
              {{%recipes}}
          WHERE
              `id` IN ('.implode(', ',array_keys($params)).')
          ORDER BY
              FIELD (id, '.implode(',', array_reverse(array_keys($params))).')
          LIMIT
              :limit',
          $params + [':limit' =&gt; $this-&gt;count]
      )
      -&gt;all();
  </code></pre>
  
  <p>How to solve with ::find() ? </p>
  
  <p>UPD: should be like</p>
  
  <pre><code>$recipes = Recipes::find()
      -&gt;where(['id' =&gt; $recipeIds])
      -&gt;orderBy(['id' =&gt; array_reverse($recipeIds)])
      -&gt;limit($this-&gt;count)
      -&gt;all();
  </code></pre>