本文介绍了whereHas在NULL值上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在其中value为NULL的地方,Has()不起作用.我与其他模型的关系是一对多的,并且我想从值等于NULL的模型中选择值.但是,除了返回特定值外,它还返回结果中的所有值
in laravel 5.5 whereHas() is not working on where value is NULL. my relationship with other model is one to many and and i want to pick the values from the model where value is equal to NULL . But instead of returning the specific values its returning all the value in result
plans = Plan::with('objectives')->with('objectives.keyResults')
->whereHas('objectives', function($query) {
$query->whereNull('entity_id');
$query->whereNull('quarter_id');
})->where('companyKey', Auth::user()->companyKey)->get();
推荐答案
您必须指定两次约束:
$plans = Plan::with(['objectives' => function($query) {
$query->whereNull('entity_id');
$query->whereNull('quarter_id');
}, 'objectives.keyResults'])
->whereHas('objectives', function($query) {
$query->whereNull('entity_id');
$query->whereNull('quarter_id');
})->where('companyKey', Auth::user()->companyKey)
->get();
这篇关于whereHas在NULL值上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!