2011-12-21 81 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%确定数据库结构。祝你好运。