Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

表 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"
      }
    ]
  }
]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

额.我是不是可以理解为,你就是想查产品2关联了哪些用户啊?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...