我有 Products hasMany Tasks
。
在任务表中查找所有没有关联记录的产品的最佳方法是什么?
我试过了:
$query->matching('Tasks', function ($q) {
return $q->where(['Tasks.product_id' => NULL});
但这似乎不起作用。
最佳答案
正如格雷格·施密特所写:notMatching是解决方案:
$query = $articlesTable->find()->notMatching('Tags');
或
$query = $articlesTable
->find()
->notMatching('Tags', function ($q) {
return $q->where(['Tags.name' => 'boring']);
});
关于associations - CakePHP 3 查找没有关联记录的记录 (hasMany),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36737768/