I have a many to one relation like shown below:
Persona Model.
$this->hasMany('PersonaId','Empleado','PersonaId')
Empleado Model.
$this->belongsTo('PersonaId','Persona','PersonaId', array("foreignKey" => true));
Suppose I have an $id of Empleado Model.
$empleado = Empleado::findFirst("EmpleadoId=$id");
I need to update records for both models given that $id so I tried the following:
$empleado->Persona->PersonaNombres = $this->request->getPost("PersonaNombres","striptags");
$empleado->Persona->PersonaApellidoPaterno = $this->request->getPost("PersonaApellidoPaterno","striptags");
$empleado->SitioId = $this->request->getPost("SitioId","int");
$empleado->TipoEmpleadoId = $this->request->getPost("TipoEmpleadoId","int");
$empleado->save();
The fields in model Empleado are saved (last two) but the related records are not. How can I save parent related records?
Thanks