有遇到 在使用yii2 Active Record 查询where 多字段中有id字段,且后面继续使用andWhere后,前面的id字段过滤莫名消失的吗

在使用yii2 Active Record查询where 多字段中有id字段,且后面继续使用andWhere后,前面的id字段过滤莫名消失的问题——方法:多增加一个只包含id字段的andWhere

$query = Order::find()->where([
       'store_id' => $this->store_id,
       'id' => $this->order_id,
       // 'is_delete' => 0,
       'is_recycle' => 0,
   ])
       ->andWhere(['id' => $this->order_id,])
       ->andWhere(['in', 'shop_id', explode(',', $currOwner->shop_ids)])
       ->with([
           'user' => function ($query) {
               $query->select([
                   'id',
                   'nickname' => 'from_base64(nickname)',
                   'binding' => "REPLACE(binding, SUBSTR(binding,4,4), '****')"
               ]);
           }
       ]);
   $order = $query->one();
   // echo $query->createCommand()->getRawSql();

上述代码中,如果去掉andWhere([‘id’ => $this->order_id,]),用createCommand()->getRawSql()生成代码即可看到,where 中的id过滤字段消失了,不知道什么地方设置的,目前的解决办法就是增加andWhere([‘id’ => $this->order_id,])。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值