2011-12-21 118 views
0

我有這個有一個模板的NPO表。模板又有一個主題。我想要檢索Npo選擇哪個主題。加入蛋糕模型php

我有以下關係建立:

NPO - 模板上npo.id = template.npoid模板 - 上theme.id = template.template_theme_id

,我使用的主題:

$this->Npo->bindmodel(array(
    'hasOne' => array(
    'NpoTemplate' => array(
     'className' => 'NpoTemplate' 
    ) 
) 
), false); 

$this->NpoTemplate->bindmodel(array(
    'hasOne' => array(
    'TemplateTheme' => array(
     'className' => 'TemplateTheme', 
     'fields' => 'TemplateTheme.html' 
    ) 
) 
), false); 

$arrUserSite = $this->Npo->find('first', array(
    'conditions'=> array(
    'Npo.address' => $user 
) 
)); 

但是它並沒有從TemplateTheme中獲取任何東西。相反,它會爲此表寫入一個單獨的查詢,並且不會在連接中考慮它。

我已經設置recursive水平3

請幫助。我真的不明白蛋糕協會是如何工作的。

問候 人士Himanshu夏爾馬

+0

'belogsTo':你的意思是......'belongsTo'? – deceze 2011-12-21 08:44:45

+0

對不起,我現在編輯它 – 2011-12-21 08:45:29

回答

1

嘗試在單一bindModel()調用設置你的人際關係。

$this->Npo->bindmodel(array(
    'hasOne' => array(
    'NpoTemplate' => array(
     'foreignKey' => false, 
     'conditions' => array(
     'Npo.id = NpoTemplate.npoid' 
    ) 
    ), 
    'TemplateTheme' => array(
     'foreignKey' => false, 
     'conditions' => array(
     'NpoTemplate.template_theme_id = TemplateTheme.id' 
    ) 
    ) 
) 
)); 


$arrUserSite = $this->Npo->find('first', array(
    'conditions' => array(
    'Npo.address' => $user 
) 
)); 

您可能需要調整bindModel設置,因爲我不是100%確定數據庫結構。祝你好運。