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

可以问一下这个JOIN到底是干了啥? #789

Open
pbw-langwang opened this issue Dec 25, 2024 · 5 comments
Open

可以问一下这个JOIN到底是干了啥? #789

pbw-langwang opened this issue Dec 25, 2024 · 5 comments

Comments

@pbw-langwang
Copy link

Description

我最近使用apijson导致了一场严重级bug,所以解决后但是不知道为什么,还望解答!

这个是数据库关系:
企业微信截图_1735003108629

其中框起来的表示要搜索的字段!

我一开始的apijson是这样的:

/** 获取我的分析列表 **/
export async function analysisListApi(params = {}, keysword) {
  // 过滤为APIJSON参数格式
  const data = {
    "[]": {
      join: `|/Project/projectId@`,
      query: 2,
      count: params.count,
      page: params.page - 1
    },
    "total@": "/[]/total"
  }

  // 设置模糊查询参数
  const likeList1 = keysword ? likeJoin(["taskName~", "taskId~", "projectId~"], keysword) : {}
  const likeList2 = keysword ? likeJoin(["projectName~", "BNId~"], keysword) : {}

  data["[]"][tableName] = {
    isDelete: 0,
    "@order": "taskCreateTime-",
    // 表字段参数
    ...params.data,
    ...likeList1
  }
  data["[]"]["Project"] = {
    uId: params.uId,
    "projectId@": `/${tableName}/projectId`,
    ...likeList2
  }
  data["[]"]["User"] = {
    id: params.uId,
    "@column": "id,name,email",
    "id@": `/${tableName}/uId`
  }
  delete data.data
  return APIList(baseURL, tableName, data)
}

结果会导致用户可以看见别的用户的数据,将join: |/Project/projectId@,改成join: |/Project/projectId@,&/User/id@,可以是可以了,但是不清楚为什么,可以解答一下吗?

@pbw-langwang
Copy link
Author

@TommyLemon

@TommyLemon
Copy link
Collaborator

TommyLemon commented Dec 29, 2024

用 INNER JOIN 前没用 User 来过滤主表。
除了 JOIN,其它都是只有引用赋值时,下面的表依赖上面的表,没有反过来的情况。
https://github.com/Tencent/APIJSON/blob/master/Document.md#3.2

#38 (comment)

@pbw-langwang
Copy link
Author

我懂了,其实我一开始我这里相当于,取出来了全部的 Task+Project 数据 FULL(并集),然后加上 &/User/id@ 后,相当于,我用这全部的数据又去用用户id过滤取了 INNER(交集),那我还是不理解这里为什么写上的 uId: params.uId 不是一个限制?

 data["[]"]["Project"] = {
    uId: params.uId,
    "projectId@": `/${tableName}/projectId`,
    ...likeList2
  }

@pbw-langwang
Copy link
Author

@TommyLemon

@TommyLemon
Copy link
Collaborator

直接浏览器抓包,或者断点调试源码,看看 params.uId 是不是传了空值

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants