Model Save() problems

Hello, I have a problem when I try to save a model.

The problem is that the model with the function $model->save() Does anything, but I change the method with $model->insert(). And now works.

So, why?

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


            $model->creation_date = date("c");


       	if ($model->save()) {


                if (isset($_POST['Leaves']['foto_leaves'])) {

                    $file = CUploadedFile::getInstance($model,'foto_leaves');

                    $foto = new Photo();

                    $foto->leaves_idleaves_parent = $model->idleaves;



This code works. But If I switch insert with save, now the code doesn´t work. So I don’t understand this behavior.

Anyone know, what is happening??

There must be somthing wrong with validation. insert() works because it does not perform validation but save() does.

save() method validates the data before saving while insert() does not validate the data…


it’s possible that when you put foto->save() some validation fails and the data is not saved…

… or you have a beforeSave() or beforeValidate() method in your Photo model that does not return true.

Try printing the errors


after $model->save();

very useful… thank’s zaccaria!