It happened few times today, I don’t know if this is bug, but model->save() sometimes save more than one row to database (PhpMySqlAdmin screenshot):
First red squared column is ID (PK, auto_increment) starting from 1000001 - as you can see 1000004 1000005 and 1000006 records are from the same time. It was on standard "Create Model" form generated by Yii.
So even if the validation is not engaded in the form it can produce that FATAL ERRORS? Should I remove the line ‘enableAjaxValidation’=>false, should we put it in bugs database?
I’m not that top Yii coder to use afterSave(). My action create was touched:
public function actionCreate()
{
$model=new Business;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Business']))
{
$model->attributes=$_POST['Business'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
));
}
For last few new inserts no duplicated rows, but what to do if it repeats?
Check your logs. If you haven’t changed any of your logging scheme it would be <site>/protected/runtime/application.log - there might be something illuminating in there. You can also check your mysql and webserver logs to look at what’s happening on that end.
I think I had the multiple insert issue at some point, but it was because I was trying to insert bad values into a field (wrong type, or too big of an int, etc - can’t really remember), which made it try the insert a couple times in a row. If that’s your case then enabling ajax validation in your view and controller might catch the issue, but I’d still say check your logs.