2011-12-21 9 views
0

하나의 템플릿이있는이 NPO 테이블이 있습니다. 템플릿에는 차례대로 테마가 있습니다. 어떤 테마가 Npo에 의해 선택되었는지 검색하고 싶습니다.cake 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 수준을 설정했습니다. 나는 케이크 협회가 어떻게 작동하는지 정말로 모른다. 하나의 bindModel() 호출의 관계를 설정

감사 히만 슈 샤르마

+0

'belogsTo' : 당신은 ...'belongsTo '를 원하셨습니까? – deceze

+0

죄송합니다. 지금 편집했습니다. –

답변

1

보십시오.

$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 설정을 조정해야 할 것입니다. 행운을 빕니다.