2011-10-14 7 views
0

다른 모델의 데이터를 같은 페이지에 표시하려고했지만 여전히 작동하지 않습니다. 는 관계 모델다른 모델의 데이터 가져 오기

에게

고객 hasMany의 작업

작업 belongsTo를 고객

작업 hasMany의 Jobtask

Jobtask belongsTo를 작업

Jobtask hasMany의 Jobtasksvehicle

Jobtasksvehicle belongsTo를 Jobtask 및 betweens이됩니다 차량

차량 hasMany의 Jobtasksvehicle

이 내 일 컨트롤러

function sch($id = null) { 
    if (!$id) { 
     $this->Session->setFlash(__('Invalid job', true)); 
     $this->redirect(array('action' => 'index')); 
    } 
    $job = $this->Job->find('first', array(
'conditions' => array('Job.id' => $id), 
'contain' => array('Customer', 
    'Jobtask' => array(
     'Jobtasksvehicle' => array(
      'Vehicle' 
     ), 
    ), 
), 

));

고객, 작업, Jobtask, Jobtasksvehicle, 차량 모델의 ​​데이터를 표시해야합니다. Customer, Job 및 Jobtask에서 데이터 표시를 가져올 수 있지만 Jobtasksvehicle 및 Vehicle 모델에서는 표시 할 수 없습니다. 각 작업에 할당 된 각 차량 (차량 모델)을 표시하려고합니다.

여기서는 jobtask 및 Vehicle 모델을 동일한 테이블에 표시하려고합니다.

<?php 
    $i = 0; 
    foreach ($job['Jobtask'] as $jobtask): 
     $class = null; 
     if ($i++ % 2 == 0) { 
      $class = ' class="altrow"'; 
     } 
    ?> 
    <tr<?php echo $class;?>> 
     <td><?php echo $jobtask['id'];?></td> 
     <td><?php echo $jobtask['job_id'];?></td> 
     <td><?php echo $jobtask['rate_id'];?></td> 
     <td><?php echo $jobtask['type'];?></td> 
     <td><?php echo $jobtask['date'];?></td> 
     <td><?php echo $jobtask['starttime'];?></td> 
     <td><?php echo $jobtask['timeband'];?></td> 
     <td><?php echo $jobtask['settlement'];?></td>  
     <td><?php echo $job['Vehicle']['vehiclemodel'];?></td> 
    </tr> 
<?php endforeach; ?> 
</table> 

?>

+0

찾기 기능이 올바른 것으로 보입니다. $ job 변수를 디버그하려고 했습니까? 당신이 찾고있는 기록에 Jobtasksvehicle AND Vehicle이 연관되어 있지 않을 수도 있습니까? –

답변

0

모든 것이 잘 될 것 같다, 당신은이

$job = $this->Job->find('first', array(
     'conditions' => array('Job.id' => $id), 
     'recursive' => 3, 
     'contain' => array('Customer', 
      'Jobtask' => array(
       'Jobtasksvehicle' => array(
       'Vehicle' 
       ), 
      ), 
     ), 
    )); 

여전히 함유 성 행동이 재귀 자동을 계산한다처럼, 3 = 재귀에서 찾기를 둘 필요가 수용 가능한 바하 빅을로드하고 있는지 확인하십시오.

책을 체크 아웃에 대한 containable behaviour 또한

는 SQL 쿼리가 수행되는 경우 SQL 쿼리 당신이 필드를 지정해야 할 수도 있습니다 나타날 경우, (당신이 작업을 사용할 수 있습니다 확인. * 오 차량. *에 모든 필드 가져 오기 ...)

관련 문제