I have two models in my project Employee visa model and visa track model.I want to store the primary key of employee visa table(ie.,employee_visa_id) in employee_visa_id field of the next table visa track. The roles of visa track is:
public function rules()
{
return [
[['emp_id', 'employee_passport_id', 'country_id', 'visa_configuration_id',], 'required'],
[['emp_id', 'employee_passport_id', 'country_id', 'visa_configuration_id','employee_visa_id'], 'integer'],
[['validity'], 'safe'],
[['remarks'], 'string'],
];
}
The roles of employee visa model is:
public function rules()
{
return [
[['emp_id', 'employee_passport_id', 'country_id','visa_type', 'expiration_date'], 'required'],
[['emp_id', 'employee_passport_id'], 'integer'],
[['expiration_date'], 'safe'],
[['remarks'], 'string'],
[['visa_type'], 'string', 'max' => 300],
];
}
In the controller I try:
foreach ($visas as $visa):
$visa->expiration_date = date('Y-m-d', strtotime($visa->expiration_date));
$visa_track->emp_id = $visa->emp_id;
$visa_track->employee_passport_id = $visa->employee_passport_id;
$visa_track->country_id = $visa->country_id;
$visa_track->visa_configuration_id = $visa->visa_type;
$visa_track->validity = $visa->expiration_date;
$emp_vid = $visa->employee_visa_id;
$visa_track->employee_visa_id = $visa->employee_visa_id;
//print_r($visa_track->employee_visa_id );die();
if($visa_track->validate())
{
// print_r($visa_track->employee_visa_id );die();
$visa_track->save();
}
else
{
$errors = $visa_track->errors;
print_r($errors);die();
}
$visa->save(false);
//$visa_track->save(false);
endforeach;
But the problem is employee_visa_id of employee visa is stored as Null value after saved in visa track.How I solve this?