I want to copy one master record to another, I crated the copy for the master (header) but now I need to copy the detail, from one header to another, so I need to access old header id and newly created header Id:
I have this on the createAction in the header controller
if ($model->save()) {
//Copia detalle
if (isset($old_id))//Es copia
$model->copiarDetalle($old_id, $model->id);
if (Yii::app()->getRequest()->getIsAjaxRequest())
Yii::app()->end();
the function:
$model->copiarDetalle($old_id, $model->id);
Just want to copy details from "old_id" to new "id", but $model->id is "0" after save() method !!
I look in Cmodel class, but i haven’t found any method that look for what I need, …
$model = $this->loadModel($id, 'CuotaDef');
$old_id = $model->id;
$model->setIsNewRecord(true); // cuando es Copia, marca como nuevo
$model->id = null; //0 <--- change from 0 to null !