Strange Scenario And Rules Behaviour

Hi Guys

I have a model with multiple scenarios in the rules.

All rules are included under one of the scenarios, so there are no rules that will ALWAYS be applicable to any scenario.

However, the following model receives no user input and is subsequently not put in any scenario. Strangely the model will not save and constantly throws an exception ‘Model could not be saved.’

$model = user::model()->findByAttributes(array('username'=>'Mark'));

$model->timestamp = time();



	$this->render('viewSuccess', array('model'=>$model));



	throw new CHttpException(404,'Model could not be saved.');


Even more strangely: If I put the model in a scenario - EVEN A SCENARIO THAT DOES NOT EXIST - then the model saves correctly.

You could therefore argue that "the model needs at least one validation rule to save", but this could not be true, because you can put it in a fake scenario (obviously with no rules) and it will save.

Any thoughts


provide rules you have.

check if you have any rules for ‘update’ scenario, as this is the default one for models feched from database (similarly new obejcts have ‘insert’ scenario).

you can also display: print_r( $model->errors ); and exit; instead of throw this 404 exception. this way you could debug what went wrong.

Hi redguy, yes that makes sence.

It must be the ‘update’ scenario that is giving me a hard time. I will check it out.

Cool print_r($model->errors) tip.

Many thanx