CakePhp 3.x select 包含行为 NULL 的地方
CakePhp 3.x select contain where row is NULL
我不清楚如何在 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;
}
这 return 类似于:
-> results
->0
->ID = 1
->Prior = null
->1
->ID = 2
->Prior = array()
->2
->ID = 3
->Prior = array()
->3
->ID = 4
->Prior = null
如何才能 return 只有 NULL
结果?
使用notMatching
(参见cookbook)
$this->find('all')
->contain(['Prior'])
->notMatching('Prior');
我不清楚如何在 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;
}
这 return 类似于:
-> results
->0
->ID = 1
->Prior = null
->1
->ID = 2
->Prior = array()
->2
->ID = 3
->Prior = array()
->3
->ID = 4
->Prior = null
如何才能 return 只有 NULL
结果?
使用notMatching
(参见cookbook)
$this->find('all')
->contain(['Prior'])
->notMatching('Prior');