tp5 withField 无效

浏览:1376 发布日期:2018/08/06 分类:求助交流

tp5 withField 对于hasOne 起作用 但是对于hasMany就变成查询全部字段,不起作用
$result = $order->where($where)
            ->with([
                'OrderGoods' => function ($query) {
                    $query->withField([
                        'goods_name', 'spec_value', 'number', 'money', 'original_money', 'img_path', 'img_name'
                    ]);
                },
                'Shop' => function ($query) {
                    $query->withField(['sid', 'shopname', 'mobile']);
                }])
            ->field([
                'oid', 'shop_id', 'money', 'original_money', 'logistics', 'is_pay' => 'status','is_comment', 'pay_time'
            ])
            ->order(['create_time'=>'desc'])
            ->paginate(10);
模型代码public function OrderGoods(){
        return $this->hasMany('OrderGoods','order_id');
    }

    public function OrderAddress(){
        return $this->hasOne('OrderAddress','order_id');
    }

    public function Shop(){
        return $this->hasOne('Shop','sid','shop_id');
    }
[ DB ] CONNECT:[ UseTime:0.006526s ] mysql:host=127.0.0.1;port=3306;dbname=waimai;charset=utf8
[ SQL ] SHOW COLUMNS FROM `ingto_order` [ RunTime:0.081241s ]
[ SQL ] SELECT COUNT(*) AS tp_count FROM `ingto_order` WHERE `oid` = 1 LIMIT 1 [ RunTime:0.003788s ]
[ SQL ] SELECT * FROM `ingto_order` WHERE `oid` = 1 ORDER BY `create_time` DESC LIMIT 0,10 [ RunTime:0.005359s ]
[ SQL ] SHOW COLUMNS FROM `ingto_order_goods` [ RunTime:0.080398s ]
[ SQL ] SELECT * FROM `ingto_order_goods` WHERE `order_id` IN (1) [ RunTime:0.004319s ]
[ SQL ] SHOW COLUMNS FROM `ingto_shop` [ RunTime:0.080811s ]
[ SQL ] SELECT `sid`,`shopname`,`mobile` FROM `ingto_shop` WHERE `sid` IN (1) [ RunTime:0.004357s ]

最佳答案
评论( 相关
后面还有条评论,点击查看>>