很酷,所以我修好了它。部分感谢布兰登为我指明了正确的方向。
由于虚拟字段的限制,我不得不采取解决方法。
因此,在我的 HrEmployee 模型中,我这样做了:
public $virtualFields = array(
'fullname' => 'CONCAT(HrEmployee.name, " ", HrEmployee.surname, " (", HrEmployee.jobTitle, ")")'
);
在我的用户模型中,我将其更改为:
class User extends AppModel {
public function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);
$this->virtualFields['fullname'] = $this->HrEmployee->virtualFields['fullname'];
}
最后,在我的 UsersController 中,我只是做了一些更改:
$hrEmployees = $this->User->HrEmployee->find('list',
array(
'fields' => array("id","fullname"),
'order' => array('HrEmployee.name ASC','HrEmployee.surname ASC')
));