我不清楚如何使用Cakephp中的contain()
获取另一行中没有引用的记录
public function initialize(array $config)
{
$this->hasmany('Prior', [
'className' => 'Prior',
'foreignKey' => 'photoID'
]);
}
public function search()
{
$query = $this->find('all')->contain(['Prior']);
return $query;
}
返回类似于:
的内容-> results
->0
->ID = 1
->Prior = null
->1
->ID = 2
->Prior = array()
->2
->ID = 3
->Prior = array()
->3
->ID = 4
->Prior = null
如何仅返回NULL
结果?
答案 0 :(得分:1)
使用notMatching
(请参阅cookbook)
$this->find('all')
->contain(['Prior'])
->notMatching('Prior');