我正在尝试查询,可以在两个关系上同时添加两个条件:
return $this->builder
->whereHas('products.comment', function ($query) {
$query->where('name', "some comment name");
})
->whereHas('products', function ($query) {
$query->where('type', 'some product type');
});
问题是它给我错误的结果。如果我想获得正确的结果,则需要像这样构成查询:
return $this->builder
->whereHas('products', function ($query) {
$query
->where('type', 'some product type')
->whereHas('comment', function ($query) {
$query->where('name', "some comment name");
})
});
现在它将正常工作。不过,我需要第一种情况,因为我想在两个单独的函数中使用它们,并在以后组合所有条件。这种差异从何而来?