I want to save each model twice in my DB.
Here is my ControllerCode:
public function actionCreate($id)
// 1. Save
// 2. Save
$model->read = 1;
For some reason the model is saved only once, eventhough I called $model->save() twice
(Maurizio Domba Cerin)
check the documentation for save() - http://www.yiiframework.com/doc/api/1.1/CActiveRecord#save-detail
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