beforesend doesn't seem to be firing


I need to check that the answer I’m inserting into the database for a specific question only has one of it’s answers labelled correct (correct=1). To that end I’m trying to intercept the save before it’s committed and make sure the correct count of answers for the question is not greater than 0. If it is I want to raise an error and not save the record.

I tried overriding the beforesave method but nothing seemed to be happening. Even if I just took everything out of the function and returned false it would still save the record.

My latest test looks like this…

    public function beforeSave() {

        if ($this->isNewRecord)

            $this->answer = 'fred';


        $this->answer = 'fred';


        return parent::beforeSave();


Trying to change the answer text to ‘fred’ but it doesn’t have any affect which leads me to think it’s not firing.

Any suggestions would be greatly welcome.



How do you save the record… note that some methods (like saveAttributes) do not call the beforeSave…

It’s being saved in just the same way as normal

	public function actionUpdate($id) {

	    $this->showUpdate = true;

		$model = $this->loadModel($id, 'Answers');

		if (isset($_POST['Answers'])) {


			if ($model->save()) {

				//$this->redirect(array('view', 'id' => $model->id));



		$this->render('update', array(

				'model' => $model,





OK… this should work…

so just to be sure… the actionUpdate() is in the controller… but the beforeSave() is in the Answers model?

That was the problem, thanks!

I had the beforesend in the controller not the model. Changed it around and it’s fine now.