【发布时间】:2021-04-29 14:07:37
【问题描述】:
当我运行这个查询时,我得到 2 行
$data->whereHas('statuses', function($q){
$q->where('statuses.title', 'P');
});
$data->whereHas('statuses', function($q){
$q->where('statuses.title', 'U');
});
但是有了这个,它不排除 2 行而是更多:
$data->whereDoesntHave('statuses', function($q){
$q->where('statuses.title', 'P');
});
$data->whereDoesntHave('statuses', function($q){
$q->where('statuses.title', 'U');
});
我需要排除从上面的代码中提取的 2 行。 我找到了实验解决方案,但我不明白这个逻辑:
$data->whereDoesntHave('statuses', function($q){
$q->where('statuses.title', 'P');
});
$data->orWhereDoesntHave('statuses', function($q){
$q->where('statuses.title', 'U');
});
为什么“或”在 whereDoesntHave 中表现得像“和”?是相反的。 为什么它有效;)?
我想要的是:“给我没有同时具有状态 P 和 U 的行”,我明白了,但是那里的“或”很奇怪。
与我的另一个问题类似:WhereNotIn inside WhereHas
【问题讨论】:
标签: mysql database laravel eloquent