Company class
public $hasMany = array(
'Person' => array(
'className' => 'Lasso.Person',
'foreignKey' => 'company_id',
)
Person class
public $belongsTo = array(
'Company' => array(
'className' => 'Lasso.Company',
'foreignKey' => 'id',
'conditions' => '',
'fields' => 'company',
'order' => ''
)
);
如何将People视图中的company_id字段作为公司的显示名称而不仅仅是company_id的值?
答案 0 :(得分:0)
public $displayField = 'companyName';
答案 1 :(得分:0)
在Person
课程中,您可以写下:
public $belongTo = array(
'Company' => array(
'className' => 'Lesso.Company',
'foreignKey' => 'company_id', // Here use company_id instead of id
.....
)
);
并且您还需要将company_id
字段放在persons
表中。