IN query for ActiveRecord

Hi,

I am wonder what’s the best way to do an IN query using Yii ActiveRecord. For example, I have an array and it has a list PK value of a table. I want to find all the records whose PK value are in the array.

What’s the Yii’s way to accomplish this.

Thanks

HLii

You could pass a CDbCriteria.




$values = array(1, 2, 3);

$criteria = new CDbCriteria;

$criteria->addInCondition('id', $values);

$results = Model::model()->findAll($criteria);



Insert the values you want into values change ‘id’ to whatever the PK is called.

Hope I’ve helped.

thanks for the pointer, I will try it out. I am sure it works.