2011-12-21 12 views
0

私は1つのテンプレートを持つこの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から何も取得しません。代わりに、このテーブルに対して別個のクエリを書き込み、結合では考慮しません。

私は助けてください3

recursiveレベルを設定しています。私は実際にケーキの関連性がどのように働いているのか分かりません

よろしく ヒマンシュー・シャーマ

+0

'belogsTo':あなたは...' belongsTo'を意味しましたか? – deceze

+0

申し訳ありません、私は今編集しました –

答えて

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 
) 
)); 

私はあなたのデータベース構造を100%確信していないので、おそらくbindModelのセットアップを調整する必要があります。がんばろう。