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

gdb: ScanList many-to-many relationship lacks support for intermediate table processing #4186

Open
PandaPy opened this issue Mar 7, 2025 · 1 comment
Labels

Comments

@PandaPy
Copy link
Contributor

PandaPy commented Mar 7, 2025

What do you want to ask?

❓ 问题描述:

在多对多关系处理中,例如用户和角色关系:

  • 用户表(sys_user)
  • 角色表(sys_role)
  • 中间表(sys_user_role)

使用 ScanList 做多对多数据绑定时,遇到以下问题:

  1. ScanList 不支持通过中间表字段(slice 类型)继续级联绑定到目标表。
  2. RelationAttrNameslice(如中间表的 []UserRole)时,调用 ScanList 会报错:

reflect: call of reflect.Value.FieldByName on slice Value

@Issues-translate-bot Issues-translate-bot changed the title gdb: ScanList 多对多关系中缺乏对中间表处理的支持 gdb: ScanList many-to-many relationship lacks support for intermediate table processing Mar 7, 2025
@pihc
Copy link

pihc commented Mar 25, 2025

这里有2种解决方案 :

  1. 先拿中间表 sys_user_role join sys_role 这里字段查 role.* ,user.id,然后再使用 ScanList 挂到 用户表返回的数据里
  2. 先拿中间表 sys_user_role join sys_role 构造出 map[userId][]*entity.SysRole,然后手动外挂到用户返回的数据里
    goframe 不是 laravel,没有提前定义好各个表之间的关系,所以不支持远程多对多

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

No branches or pull requests

2 participants