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

[BUG]有两个字段通过连表查询获取,恰巧这两个字段名一样,在对连表的第二个字段进行筛选操作时,获取不到结果 #151

Closed
wade0817wang opened this issue Jan 15, 2020 · 1 comment
Labels
🐛bug Something isn't working

Comments

@wade0817wang
Copy link

wade0817wang commented Jan 15, 2020

bug 描述

有两个字段通过连表查询获取,恰巧这两个字段名一样,在对连表的第二个字段进行筛选操作时,获取不到结果。此时sql语句打印出来的where语句拼写的第一个连表的表名。

期望结果

能够正常筛选出结果

复现代码 [提供可复现的代码,仓库,或线上示例]

info.AddField("角色", "description", db.Varchar).FieldJoin(types.Join{
	Table:     "gcf_role", // 连表的表名
	Field:     "role_id",  // 要连表的字段
	JoinField: "id",       // 连表的表的字段
}).FieldFilterable(types.FilterType{Operator: types.FilterOperatorLike})
info.AddField("资源", "description", db.Varchar).FieldJoin(types.Join{
	Table:     "gcf_permission", // 连表的表名
	Field:     "permission_id",  // 要连表的字段
	JoinField: "id",             // 连表的表的字段
}).FieldFilterable(types.FilterType{Operator: types.FilterOperatorLike})

版本信息:

  • GoAdmin 版本: [e.g. 1.1.7]
  • golang 版本
  • 浏览器环境
  • 开发环境 [e.g. mac OS]

出现问题原因

/plugins/admin/modules/table/table.go 650~660行, 判断拼接哪个field时,应该增加join 表的判断.

keys := strings.Split(key, "_goadmin_join_")
if len(keys) > 1 {
	if field := tb.info.FieldList.GetFieldByFieldName(keys[1]); field.Exist() && field.Join.Table != "" {
		wheres += field.Join.Table + "." + filterFiled(keys[1], connection.GetDelimiter()) + " " + op.String() + " ? and "
		if op == types.FilterOperatorLike && !strings.Contains(value, "%") {
			whereArgs = append(whereArgs, "%"+value+"%")
		} else {
			whereArgs = append(whereArgs, value)
		}
	}
}

完全可能出现连接两个不同的表,file name相同

@wade0817wang wade0817wang added the 🐛bug Something isn't working label Jan 15, 2020
@chenhg5
Copy link
Collaborator

chenhg5 commented Aug 2, 2020

时间有点久,新版本中这个问题应该已被解决。

@chenhg5 chenhg5 closed this as completed Aug 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants