2017-02-15 57 views
0

目前尚不清楚对我怎样才能在CakePHP中CakePHP的3.X选择包含其中row是NULL

public function initialize(array $config) 
{   
    $this->hasmany('Prior', [ 
     'className' => 'Prior', 
     'foreignKey' => 'photoID' 
    ]); 
} 

public function search() 
{ 
    $query = $this->find('all')->contain(['Prior']); 
    return $query; 
} 

这将返回类似的东西取不具有的其他行中的引用记录使用contain()

-> results 
    ->0 
    ->ID = 1 
    ->Prior = null 

    ->1 
    ->ID = 2 
    ->Prior = array() 

    ->2 
    ->ID = 3 
    ->Prior = array() 

    ->3 
    ->ID = 4 
    ->Prior = null 

如何仅返回NULL结果?

回答

1

使用notMatching(见cookbook

$this->find('all') 
    ->contain(['Prior']) 
    ->notMatching('Prior'); 
+0

这么简单,非常感谢你! – Joost