Hi, I need to delete records from db by chunks using CDbCriteria. I do it this way
$criteria->select = 't.id';
$chank_num = 5;
$criteria->limit = $chank_num;
do{
$update_ids = array();
$res = $model->findAll($criteria);
if(!empty($res)) foreach ($res AS $item){
$update_ids[] = $item->id;
}
if(!empty($update_ids)){
$temp_criteria = $criteria;
$temp_criteria->addInCondition('id', $update_ids);
$res = $model->deleteAll($temp_criteria);
$total_cnt += count($update_ids);
}
}while(count($update_ids) == $chank_num);
But the problem is that for the first time loop goes well and deletes 5 records but the second time $criteria has additional condition (id IN array of ids found in first loop). It looks like addInCondition affects not only $temp_criteria but $criteria too. Can anybody give me a hint whats going wrong?