How to use 'IN (1,2,3)' with findAll?

前端 未结 2 556
不思量自难忘°
不思量自难忘° 2021-02-18 21:42

I need to get a couple of Students from the database, and I have their primary keys in a comma-separated string.

Normally using SQL it would be something like:



        
2条回答
  •  长发绾君心
    2021-02-18 21:53

    You can use findAllByAttributes method also:

    $a=array(1,2,3,4);
    $model = Student::model()->findAllByAttributes(array("id"=>$a));
    

提交回复
热议问题