2013-06-29 172 views
0
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的值?Cakephp關係問題

回答

0
public $displayField = 'companyName'; 
+0

我已經在我的公司模型中有。 –

+0

我想通了!需要做到這一點在我看來: $ people = $ this-> Company-> Person-> find('list'); $ this-> set(compact('people')); –

+0

@JustinYoung你做了什麼你的看法? – Jelmer

0

在你Person類,你可以寫:

public $belongTo = array(
    'Company' => array(
      'className' => 'Lesso.Company', 
      'foreignKey' => 'company_id', // Here use company_id instead of id 
      ..... 
    ) 
); 

,你也需要把company_id領域persons表。