whereHas 不适用于 NULL 值 [英] whereHas is not working on NULL value

查看:24
本文介绍了whereHas 不适用于 NULL 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 laravel 5.5 whereHas() 不能处理值为 NULL 的地方.我与其他模型的关系是一对多的,我想从模型中选择值等于 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 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆