save() is undefined in CActiveRecord model?

I have a problem calling save() or update() in a model when I call these inside another models actionDelete.

Specifically this:

public function actionDelete($id)


        $model = $this->loadModel($id);

        if (Yii::app()->request->isPostRequest) {

            // we only allow deletion via POST request

            $visits = $model->visits;

            if (count($visits) > 0) {

                foreach ($visits as $visit) {

                    $visit->peopleCount = $visit->peopleCount - 1;




            PersonVisit::model()->deleteAll('personId=:personId', array(':personId'=>$id));


            // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser

            if (!isset($_GET['ajax']))

                $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));



            throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');


… fails in $visit->save() with the error message in the description…

I have used save() and update() in the same controller for the Visit model w/o any problems. What’s special about delete action?

Nothing, you’re using “.” instead of “->”:


Oh, well. What a stupid mistake! Thanks for pointing out.