Save() not working after loading model

So for some reason after I load a model and try to save it, it does not work. I checked rules, access rules but still nothing. I have 3 simple lines:




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

	$model->setAttributes(array('title'=> 'Saved'));

	$model->save();

It doesn’t even work if I just try to load and save.




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

	if($model->save())

			echo $model->title;

Weirdly my update function works but like I said I checked access rules and my function is allowed so I don’t know why it is not saving. Is there any way I can print out errors on why save just doesn’t actually save?

Does


$model->save(false);

work?

Yes yes it does, but what does that false do? By the way nice to see a fellow Hungarian on these boards :)

That “false” disables validation on save.( CActiveRecord::save() ) Check your validation rules to find the one that causes the problem. Egyébként szia! :)

Sometime it happens when you change model table schema and you don’t want to generate the model again for good reasons … In that case you can use this before calling save() :

                                  foreach($_POST['YourModel'] as $k=>$v){


				if($model->hasAttribute($k)){


					$model->setAttribute($k, $v);


				}


		              }


		                


                                  $model->save();

when ever you face such problem try this debugging technique

if(!$model->save){

$msg = print_r($model->getErrors(),1);

throw CHttpException(400,'data not saving: '.$msg );

}

this exception will give you exact error why save is not working

Wao it’s work what does false mean in save(false)

Read the thread phtamas already said

OP: Does the loadModel(39) actually return something?