【发布时间】:2017-04-25 09:08:51
【问题描述】:
我有三张桌子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',
],
]);
有没有办法实现这一点并根据某些过滤条件两次包含相同的模型?
【问题讨论】:
标签: cakephp model-associations cakephp-3.4