我有三张桌子ServerScans
,,,QueuedJobs
ReportMalware
ReportMalware
有一列type
包含诸如mail
,之类的值abc
。
我将 ServerScans 查询为
$scan = $this->ServerScans->get($id, [
'contain' => [
'QueuedJobs',
'QueuedJobs.ReportMalware',
],
]);
并考虑使用 for 循环将恶意软件报告分为两组
<h2>Mail report</h2>
<?php foreach($scan->queued_jobs->report_malware as $m): ?>
<?php if ($m->type == 'mail'): ?>
<?= $m->comment ?>
<?php endif; ?>
<?php endforeach;?>
<h2>Abc report</h2>
<?php foreach($scan->queued_jobs->report_malware as $m): ?>
<?php if ($m->type == 'abc'): ?>
<?= $m->comment ?>
<?php endif; ?>
<?php endforeach;?>
这将需要更多的时间来执行。
我想要的是保持它包含
$scan = $this->ServerScans->get($id, [
'contain' => [
'QueuedJobs',
'QueuedJobs.ReportMalware.mail',
'QueuedJobs.ReportMalware.abc',
],
]);
有没有办法实现这一点并根据某些过滤条件两次包含相同的模型?