Two tables in one data provider

I have here two types of employee - HDS and Administrator. I have put all their common attributes in the employee table. So I have three tables: Administrator, HDS, employee. Thus, it’s like the administrator and the HDS are the subsets of employee.

My problem is that I can’t join the employee and the HDS table in one dataprovider. I already used the “with” in the criteria in the action Index of the HDS controller. However I keep on getting this error - “CException: Property “Hds.fname” is not defined.”. The ‘fname’ is an attribute of the employee table. This is the relation of the Hds model: “‘employee’ => array(self::BELONGS_TO, ‘Employee’, ‘employee_id’)”.

So how do I join the two tables properly? I will also apply the solution for the administrator and employee module.

Hope for reply. Thanks!

You should access properties of related objects this way:




$hds->employee->fname;



Here is a part of hds’s _view.php file.




<b><?php echo CHtml::encode($data->getAttributeLabel('fname')); ?>:</b>

	<?php echo CHtml::encode($data->fname); ?>

	<br />



So where should I put that code?

$data is an object of Hds class, so $data->employee->fname.

Thank you very much. Now it works!