AR save() doesn't without error


I’m trying to save a model entry

but it just doesn’t go through

I tried looking at the CWebLogRoute but I see no SQL genereted for the save

so how can I see what sql will be executed in the save , so I can test it manuelly ?

is somehing like this available ? or some other logging feature which could give me some clues ?

cause I’m a bit stuck

here my code just in case

$meetingMark = new MeetingMark();

        		$meetingMark->mark = $mark;

        	    $meetingMark->subjectid = $meetingId;

        		$meetingMark->userid = $userid;

        	    $meetingMark->surveyid = $surveyid;

        	    $meetingMark->subjectType = 'meeting';

        	    $meetingMark->type = $type;

        	    $meetingMark->surveyType = 'checklist';


        	        $debug .= '<br/>SUCCESS :: added to DB Mark :'.$type.' = '.$mark;


        	        $debug .= '<br/>ERROR :: couldnt add to DB Mark :'.$type.' = '.$mark;

Hi Tibor,

When you call save() it does attribute validation there before saving to database.There may be validation rule violation in your code.



you ahould call validate() before save and than Yii will populate the errors for that model.

so in your case something like this:



  $debug .= '<br/>SUCCESS :: added to DB Mark :'.$type.' = '.$mark; 


  $debug .= '<br/>ERROR :: couldnt add to DB Mark :'.$type.' = '.$mark.'<br />'.CHtml::errorSummary(meetingMark); 


Thanks for the help guys

I tried your validation code Greg

and that gave me the path after echoing the $model->getErrors

to find the violation rules ,

offcourse I was the bug :wink:

Thanks for the help guys

Check your database, do your fields match the insert query you are trying to do -check model attributes?

Check your rules

Check the result of your validation


For profiling you can use this article

Db profiling

If the data you save are not fit with the table schema, you’ll encounter this.

Check your database schema, especially some columns that are not allowing data to be null.