public function actionLink() { // $lessons = Lesson::model()->findAllByAttributes(array('mediaType'=>'link')); $criteria = new CDbCriteria(); $criteria->condition = "mediaType='' and mediaUri!=''"; $lessons = Lesson::model()->findAll($criteria); foreach ($lessons as $lesson) { $link = new MediaLink(); $link->url = $lesson->mediaUri; $link->title = $lesson->title; if ($link->save()) { $lesson->mediaType = "link"; $lesson->mediaId = $link->getPrimaryKey(); $lesson->save(); } } }