通过with 关联关系如何查询从表信息
来源:13-17 获取用户信息
慕粉1472091201
2017-11-12
老师,定义关联关系的时候能传入参数会报错,例如:
//定义订单与商品是多对多关系
public function orDeals($data=[]){
$data['status']=>1
return $this->belongsToMany('Deal','OrderProduct','product_id','order_id')
->where($data);
}
public function getorProducts($sdata=[],$data=[]){
$sdata['status'] = 1;
$result = $this->where($sdata)->field('id,order_no,total_price,create_time,snap_address')
->with('orDeals($data)') <--------这里不能传入参数,否则会被误为是方法而不是关系
->select(); 《----有没有其他解决方法,可以查询从表Deal的信息
//
echo $this->getLastSql();
print_r($result);exit();
return $result;写回答
1回答
-
7七月
2017-11-13
建议分两次查询。
00
相似问题
多对多关联如何使用条件查询
回答 1
查询两个表的数据语句应该怎样写
回答 1