Hi folks,
I am currently trying to create a dropdown menu for a table, and I cant seem to get my head around this.
That's all well a good but I am trying to create this on an association table and I do not want to bring back options for data that is already associated. To explain this further, the dropdown is used to populate the employee_id name on a table that has these fields: -
The table itself is called norm_company_employee (with the model name NormCompanyEmployee) and it contains the relation: -
The ref_employee table is simple and looks like this: -
All relations are fine - they have been tested.
As of now, there are still a few 'employee_id' fields in norm_company_employee that are NULL, and these are the fields I am trying to populate. I have unique attributes validator in place which conforms to the SQL index but I would like - for convenience - to only have the dropdown only show employees that are not yet associated. So, the code needs to check the relational ship and only SELECT from ref_employee (RefEmployee) where the ID of the ref_employee record is not already linked to the norm_company_employee.employee_id column.
I hope that makes sense?
I am sure the solution is probably not that difficult but I cant seem to get my head around it.
Thanks in advance.
I am currently trying to create a dropdown menu for a table, and I cant seem to get my head around this.
$employees = CHtml::listData(RefEmployee::model()->findAll("company_id = {$model->company_id}"), 'id', 'employee_name');
That's all well a good but I am trying to create this on an association table and I do not want to bring back options for data that is already associated. To explain this further, the dropdown is used to populate the employee_id name on a table that has these fields: -
ID - company_id - employee_name - employee_id
The table itself is called norm_company_employee (with the model name NormCompanyEmployee) and it contains the relation: -
'employee' => array(self::BELONGS_TO, 'RefEmployee', 'employee_id'),
The ref_employee table is simple and looks like this: -
ID - company_id - employee_name
All relations are fine - they have been tested.
As of now, there are still a few 'employee_id' fields in norm_company_employee that are NULL, and these are the fields I am trying to populate. I have unique attributes validator in place which conforms to the SQL index but I would like - for convenience - to only have the dropdown only show employees that are not yet associated. So, the code needs to check the relational ship and only SELECT from ref_employee (RefEmployee) where the ID of the ref_employee record is not already linked to the norm_company_employee.employee_id column.
I hope that makes sense?
I am sure the solution is probably not that difficult but I cant seem to get my head around it.
Thanks in advance.