为了账号安全,请及时绑定邮箱和手机立即绑定

Yii2 - 为空时忽略“或”条件

Yii2 - 为空时忽略“或”条件

PHP
陪伴而非守候 2021-10-22 15:25:12
我有这个工作正常的查询$order_items= OrderItem::find()->where(['location_id'=>$model->location_name,'instructor_id'=>$model->instructor_name])->andwhere(['between', 'date', $model->from_date, $model->to_date ])->all();但是当$model->instructor_name为空或空时,我得到空结果。所以我想忽略何时instructor_id为空'instructor_id'=>$model->instructor_name or instructor_id'=> Null我怎么能做到这一点?
查看完整描述

2 回答

?
慕哥6287543

TA贡献1831条经验 获得超10个赞

你应该使用andFilterWhere()


$order_items = OrderItem::find()

   ->where(['location_id' => $model->location_name])

   ->andFilterWhere(['instructor_id' => $model->instructor_name])

   ->andwhere(['between', 'date', $model->from_date, $model->to_date ])

   ->all();


查看完整回答
反对 回复 2021-10-22
?
慕标5832272

TA贡献1966条经验 获得超4个赞

$order_items= OrderItem::find()

->where(['location_id'=>$model->location_name,'instructor_id'=>$model->instructor_name])

->andWhere(['not', ['instructor_id' => null]])

->andwhere(['between', 'date', $model->from_date, $model->to_date ])->all();

或者添加以下内容


  ->andWhere(['<>', 'instructor_id', null])

或者


 ->andWhere('instructor_id IS NOT NULL')


查看完整回答
反对 回复 2021-10-22
  • 2 回答
  • 0 关注
  • 217 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号