Multiple inserts by Yii onSubmit - is it BUG?

Hi

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.

Any clues where to debug? ???

I had a similar issue some days ago.

A possible error is to have enableAjaxValidation in CForm (in the view) and NOT in the controller, this can result in multiple insert.

In my CREATE form I have:




<?php $form=$this->beginWidget('CActiveForm', array(

	'id'=>'business-form',

	'enableAjaxValidation'=>false,

)); ?>



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?

That means that you are not in my case.

Maybe you did something of AfterSave?

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.

Hi there,

set ‘enableAjaxValidation’=>false, in _form.php if you don’t need it,

It will store only one record.

other wise follow the note to turn it on if you need it.