0
votes

I have three tables

Job Employee EmployeesJob --------- -------- ---------------------- id id id name name job_id employee_id work_hours

The relationship is hasMany through (The Join Model[EmployeesJob]) What I want to do is when add a new Job, admin can choose one or many employees, related information will store in EmployeesJob and Job. in job/admin_add

echo $this->Form->input('EmployeesJob.employee_id',array('options'=>$employees, 'label'=>'Employee'));

it displays all employees, but admin only can choose one of them, also it doesn't insert a new row in EmployeesJob, My job table has other association tables(HABTM, belong to), so I am not sure saveAssociated($this->request->data) can do all the stuff.

I need help, Many Thanks

1

1 Answers

0
votes

For multiple selection of employees you should write the following:

echo $this->Form->input('EmployeesJob.employee_id][',array('options'=>$employees, 'label'=>'Employee', 'multiple' => 'multiple'));

To save multiple records, you should write the following in your controller's code:

$this->Job->saveAssociated($this->request->data, array('deep' => true));

This link might also help you to achieve the same: CakePHP saving Foreign Key Issue