表 User
id name
表 Order
id user_id
表 Goods
id order_id name
获取所有数据
1. $this->with(['User','Goods'])->limit($pages,$get['limit'])->select();
得到数据
[
{
"id": 1,
"username": "用户A",
"Goods": [
{
"id": 1,
"name": "产品1"
},
{
"id": 2,
"name": "产品2"
},
{
"id": 3,
"name": "产品3"
}
]
},
{
"id": 2,
"username": "用户A",
"Goods": [
{
"id": 4,
"name": "产品4"
},
{
"id": 2,
"name": "产品2"
}
]
},
{
"id": 3,
"username": "用户B",
"Goods": [
{
"id": 1,
"name": "产品1"
},
{
"id": 7,
"name": "产品7"
}
]
}
]
现在想关联查询获得如下数据,不知道怎么操作
[
{
"id": 1,
"username": "用户A",
"Goods": [
{
"id": 2,
"name": "产品2"
}
]
},
{
"id": 2,
"username": "用户A",
"Goods": [
{
"id": 2,
"name": "产品2"
}
]
}
]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…