oceatoon
(Oceatoon)
September 15, 2011, 10:22am
1
Hi
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';
if($meetingMark->save())
$debug .= '<br/>SUCCESS :: added to DB Mark :'.$type.' = '.$mark;
else
$debug .= '<br/>ERROR :: couldnt add to DB Mark :'.$type.' = '.$mark;
aruna470
(Aruna470)
September 15, 2011, 10:29am
2
Hi Tibor,
When you call save() it does attribute validation there before saving to database.There may be validation rule violation in your code.
Thanks
Aruna.
gregmolnar
(Molnargerg)
September 15, 2011, 10:30am
3
you ahould call validate() before save and than Yii will populate the errors for that model.
so in your case something like this:
if($meetingMark->validate()){
$meetingMark->save();
$debug .= '<br/>SUCCESS :: added to DB Mark :'.$type.' = '.$mark;
}else{
$debug .= '<br/>ERROR :: couldnt add to DB Mark :'.$type.' = '.$mark.'<br />'.CHtml::errorSummary(meetingMark);
}
oceatoon
(Oceatoon)
September 15, 2011, 4:36pm
4
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
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
var_dump($model->getErrors());
iivano71
(Igor Zg1987)
September 16, 2011, 7:25am
6
For profiling you can use this article
Db profiling
lornechang
(Lornereg)
September 16, 2011, 9:12am
7
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.