2011-12-04 3 views
1

내가 뭘 잘못하고 있는지 알고 싶습니다.cakephp 테이블 관계가 비어 있습니다.

var $belongsTo = array(
    'Residence' => array(
     'className' => 'Residence', 
     'foreignKey' => 'residence_id', 
     'conditions' => '', 
     'fields' => '', 
     'order' => '' 
    ) 
); 

레지던스 모델 난이

<?php 
class ProprietairesController extends AppController { 

var $name = 'Proprietaires'; 

    function index() { 
    $this->Proprietaire->recursive = 1; 
$this->set('proprietaires', $this->paginate()); 

$residences = $this->Proprietaire->Residence->find('list'); 
$this->set(compact('residences')); 
    } 

} 
?> 

BU처럼 거주 이름을 얻으려고

proprietaire에서
var $hasMany = array(
'Proprietaire' => array(
     'className' => 'Proprietaire', 
     'foreignKey' => 'residence_id', 
     'dependent' => true, 
     'conditions' => '', 
     'fields' => '', 
     'order' => '', 
     'limit' => '', 
     'offset' => '', 
     'exclusive' => '', 
     'finderQuery' => '', 
     'counterQuery' => '' 
    ) 
); 

:

나는이 관계를

Proprietaire 모델이 내 proprietaire보기

<?php foreach ($proprietaires as $proprietaire): ?> 
     <?= print_r($proprietaire['Residence'])?> 
     <tr <?= $this->Cycle->css(array('list-line-odd', 'list-line-even'),true); ?>> 
      <td><?php echo $proprietaire['Proprietaire']['nom']; ?>&nbsp;</td> 
      <td style="text-align: center;"><?php echo $proprietaire['Proprietaire']['prenom']; ?>&nbsp;</td> 
      <td style="text-align: center;"><?php echo $proprietaire['Residence']['nom']; ?>&nbsp;</td> 
      <td class="actions"> 
       <?php echo $this->Html->link(__('Modifier', true), array('action' => 'edit', $proprietaire['Proprietaire']['id'])); ?> 
       <?php echo $this->Html->link(__('Supprimer', true), array('action' => 'delete', $proprietaire['Proprietaire']['id']), null, sprintf(__('&Ecirc;tes-vous certain de vouloir supprimer # %s?', true), $proprietaire['Proprietaire']['id'])); ?> 
      </td> 
     </tr> 
    <?php endforeach; ?> 

에서 t는 인 print_r (proprietaire [ '레지던스'] 나에게 빈 배열을 제공합니다.

Array () 1 Array () 1 Array () 1 Array () 1 Array () 1 Array () 1 Array () 1 Array () 1 Array () 1 Array () 1 Array () 1 Array () 1 Array () 1 Array () 1 Array () 1 

무엇이 좋지 않습니까? 내 테이블 관계?

귀하의 도움에 감사드립니다.

+0

에서 다음은 홍보 ($ 주택)''에서 무엇을 얻을 수 있습니까? 또한, 당신은 케이크가 생성하는 SQL 쿼리를 보았습니까? – bjudson

+0

dabase 테이블을 올바르게 설정했는데 테이블에 실제로 "거주"데이터가 있습니까? –

답변

0

너무 좋아 찾아 당신이 당신의 레지던스 모델

var $displayField = 'nom'; 

에 displayField 속성을 설정했는지 확인 또는 수행

다른
$residences = $this->Proprietaire->Residence->find('list', array('Residence.id', 'Residence.nom')); 

2로 쿼리 설정 디버그 수준을 확인하고 추가 레이아웃이나 뷰

<?php echo $this->element('sql_dump'); ?> 
관련 문제