Beforesave Isn't Working

This is the class

abstract class TrackStarActiveRecord extends CActiveRecord


    protected function beforeSave()


        if(Yii::app()->user !== null)

            $id = Yii::app()->user->id;


            $id = 1;


            $this->create_user_id = $id;

        $this->update_user_id = $id;

        return parent::beforeSave();


    public function behaviors()


        return array(










behaviors is functioning fine, but beforeSave() doesn’t trigger when I’m trying to add a comment. What am I doing wrong?

If anyone is experiencing the same issue, it’s due to validation. beforeSave() isn’t triggered unless validation is successful.

In this case Comment model had create_user_id and update_user_id as required, but these values are populated only after validation is done. Modifying the rules() in Comment model fixed my problem.

Ya… But are you inserting create_user_id and update_user_id in backend…?? so you have not put this field in required.