Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关联查询问题 #14

Open
gzxy-0102 opened this issue Feb 9, 2023 · 5 comments
Open

关联查询问题 #14

gzxy-0102 opened this issue Feb 9, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@gzxy-0102
Copy link

能不能像APIJSON官方一样 支持这种嵌套查询
image

@glennliao
Copy link
Owner

目前不支持嵌套
支持以下方式:

in

{
  "User": {
    "userId": "10002"
  },
  "todo[]":{
    "Todo": {
      "userId@": "User/userId"
    }
  }
}

out:

{
  "User": {
    "createdAt": "2022-10-24 17:06:09",
    "id": 4,
    "realname": "史强",
    "userId": "10002",
    "username": "shiqiang"
  },
  "todo[]": [
    {
      "Todo": {
        "createdAt": "2022-10-24 17:59:47",
        "deletedAt": null,
        "id": 24,
        "note": null,
        "partner": "10003",
        "title": "找丁仪发呆",
        "todoId": null,
        "userId": "10002"
      }
    },
    {
      "Todo": {
        "createdAt": "2022-10-24 18:00:03",
        "deletedAt": null,
        "id": 26,
        "note": null,
        "partner": "10003",
        "title": "找丁仪发呆",
        "todoId": null,
        "userId": "10002"
      }
    },
  ],
  "ok": true,
  "code": 200,
  "msg": "success",
  "span": "31.4325ms"
}

@gzxy-0102
Copy link
Author

目前不支持嵌套 支持以下方式:

in

{
  "User": {
    "userId": "10002"
  },
  "todo[]":{
    "Todo": {
      "userId@": "User/userId"
    }
  }
}

out:

{
  "User": {
    "createdAt": "2022-10-24 17:06:09",
    "id": 4,
    "realname": "史强",
    "userId": "10002",
    "username": "shiqiang"
  },
  "todo[]": [
    {
      "Todo": {
        "createdAt": "2022-10-24 17:59:47",
        "deletedAt": null,
        "id": 24,
        "note": null,
        "partner": "10003",
        "title": "找丁仪发呆",
        "todoId": null,
        "userId": "10002"
      }
    },
    {
      "Todo": {
        "createdAt": "2022-10-24 18:00:03",
        "deletedAt": null,
        "id": 26,
        "note": null,
        "partner": "10003",
        "title": "找丁仪发呆",
        "todoId": null,
        "userId": "10002"
      }
    },
  ],
  "ok": true,
  "code": 200,
  "msg": "success",
  "span": "31.4325ms"
}

这样确实好使 我尝试过 但是还是嵌套数据对前端友好点吧

@glennliao glennliao added the enhancement New feature or request label Feb 10, 2023
@glennliao
Copy link
Owner

我个人前端使用上来讲,其实都一样。 先把其它完善下,再来增加对这种嵌套的支持吧

@TommyLemon
Copy link

TommyLemon commented Feb 13, 2023

能不能像APIJSON官方一样 支持这种嵌套查询 image

这种嵌套写法不支持 JOIN,还是建议把 User 和 comment[] 放在同一层级
image

https://github.com/Tencent/APIJSON/blob/master/Document.md#3.2

@TommyLemon
Copy link

TommyLemon commented Feb 13, 2023

目前不支持嵌套 支持以下方式:
in

{
  "User": {
    "userId": "10002"
  },
  "todo[]":{
    "Todo": {
      "userId@": "User/userId"
    }
  }
}

out:

{
  "User": {
    "createdAt": "2022-10-24 17:06:09",
    "id": 4,
    "realname": "史强",
    "userId": "10002",
    "username": "shiqiang"
  },
  "todo[]": [
    {
      "Todo": {
        "createdAt": "2022-10-24 17:59:47",
        "deletedAt": null,
        "id": 24,
        "note": null,
        "partner": "10003",
        "title": "找丁仪发呆",
        "todoId": null,
        "userId": "10002"
      }
    },
    {
      "Todo": {
        "createdAt": "2022-10-24 18:00:03",
        "deletedAt": null,
        "id": 26,
        "note": null,
        "partner": "10003",
        "title": "找丁仪发呆",
        "todoId": null,
        "userId": "10002"
      }
    },
  ],
  "ok": true,
  "code": 200,
  "msg": "success",
  "span": "31.4325ms"
}

这样确实好使 我尝试过 但是还是嵌套数据对前端友好点吧

未必更加友好,尤其是对于客户端来说,建立实体类(JavaBean/Entity 等) 还是把 User 和 List 独立开更好,而不是

class User {
   List<Comemnt> commentList;
}

如果是这种,那你想想结构上还可能有各种嵌套组合导致不方便处理,以及对应带来的循环引用导致内存泄漏等问题

class Comemnt {
   User owner;
}
class User {
   List<Moment> momentList;
}
class Moment {
   User publisher;
   List<Comment> commentList;
}

...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants