Hi,
I´m having issues with an ActiveForm that is used to save data into 3 tables which are related. Here is the create action from the controler:
public function actionCreate()
{
$a=new Persona;
$b=new Empleado;
$c=new PersonaTelefono;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Persona'],$_POST['Empleado'],$_POST['PersonaTelefono']))
{
$a->attributes=$_POST['Persona'];
$b->attributes=$_POST['Empleado'];
$c->attributes=$_POST['PersonaTelefono'];
$error=false;
$transaction = Yii::app()->db->beginTransaction();
try{
if(!$a->save()){
throw new CException(CHtml::errorsummary($a));
}
$b->persona_id=$a->id;
$c->persona_id=$a->id;
if(!$b->save()){
throw new CException(CHtml::errorsummary($<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='B)' />);
}
if(!$c->save()){
throw new CException(CHtml::errorsummary($c));
}
$transaction->commit();
Yii::app()->user->setFlash('success', "Registro creado con éxito");
}
catch(Exception $e){
$transaction->rollback();
$error = $e->getMessage();
Yii::app()->user->setFlash('error', "No se creó el registro");
}
if (!$error) {
$this->redirect(array('create'));
}
}
$this->render('create',array(
'a'=>$a,
'b'=>$b,
'c'=>$c,
));
}
The code is working but it genereates a double entry in postgresql DB, I´ve been struggling for a while an searching on the forum but with no luck so far.