Order By Field IN Yii2

前端 未结 1 799
余生分开走
余生分开走 2021-01-19 18:33

I got this problem and not found any solution with yii instrument. Someone know how to solve this problem ?

Eventually, i used this bad code

$params         


        
相关标签:
1条回答
  • 2021-01-19 18:43

    Try that:

    $recipes = Recipes::find()
        ->where(['in', 'id', $recipeIds])
        ->orderBy([new \yii\db\Expression('FIELD (id, ' . implode(',', array_reverse(array_keys($params))) . ')')])
        ->limit($this->count)
        ->all();
    

    For use orderBy with FIELD (...) see https://github.com/yiisoft/yii2/issues/553

    0 讨论(0)
提交回复
热议问题