How to save same model twice in DB

Hey guys,

I want to save each model twice in my DB.

Here is my ControllerCode:

	public function actionCreate($id)


		$model=new pm;





		         // 1. Save


			// 2. Save

			$model->read = 1;








For some reason the model is saved only once, eventhough I called $model->save() twice



check the documentation for save() -

the record is inserted if the properta isNewRecord is true… the first time you save the record this properties is set to false… so the second time save() updates the record…

try to set $model->isNewRecord to false before calling save() the second time…

Hmm when doing

$model->isNewRecord = true;

I get the error:

Integrity constraint violation: 1062 Duplicate entry '40' for key 'PRIMARY' 

That means I have to increase the pk manually…

Is there a better way?


Never done that, but try something like

$model->isNewRecord = true

unset($model->pk);  // or $model->pk = NULL (or FALSE)

Because it looks like is trying to INSERT again but reusing the same PK