다른 모델의 데이터를 같은 페이지에 표시하려고했지만 여전히 작동하지 않습니다. 는 관계 모델다른 모델의 데이터 가져 오기
에게고객 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>
?>
찾기 기능이 올바른 것으로 보입니다. $ job 변수를 디버그하려고 했습니까? 당신이 찾고있는 기록에 Jobtasksvehicle AND Vehicle이 연관되어 있지 않을 수도 있습니까? –