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

'Omitempty' in orm tag is no longer take effect when select/update/insert using struct #3204

Closed
zhangyuyu opened this issue Dec 14, 2023 · 0 comments
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version.

Comments

@zhangyuyu
Copy link
Contributor

zhangyuyu commented Dec 14, 2023

1. What version of Go and system type/arch are you using?

go version go1.21.3 darwin/arm64

2. What version of GoFrame are you using?

version change:go: upgraded github.com/gogf/gf/v2 v2.5.7-0.20231114121049-5580ac9475ae => v2.6.0-beta.0.20231214061831-33584506ab17

3. Can this issue be re-produced with the latest release?

yes, occurred in latest version which is 3358450

4. What did you do?

struct po.SystemRole:

type SysRole struct {
	g.Meta `orm:"table:t_sys_role, do:true"`

	ID         interface{} `orm:"f_id,omitempty"           ` // 角色 ID
	Name       interface{} `orm:"f_name,omitempty"         ` // 角色名称
	NameCn     interface{} `orm:"f_name_cn,omitempty"      ` // 中文角色名称
	Type       interface{} `orm:"f_type,omitempty"         ` // 角色类型 Platform/Business
	Enabled    interface{} `orm:"f_enabled"                ` // 是否启用
	MenuNames  interface{} `orm:"f_menu_names,omitempty"   ` // 菜单名称列表
	Desc       interface{} `orm:"f_desc,omitempty"         ` // 角色描述
	UpdateTime interface{} `orm:"f_update_time,omitempty" `  // 更新时间
	CreateTime interface{} `orm:"f_create_time,omitempty" `  // 创建时间
}

select logic:

condition := &po.SysRole{Name: "SUPER_ADMIN", NameCn: ""}

	var record *entity.SysRole
	if err := s.Ctx(ctx).Where(condition).Scan(&record); err != nil {
		return nil, errs.NewOperateDBError(ctx, s.Table(), err)
	}

update logic:

        out  := &po.SysRole{Type: "Business"}
	if _, err := s.Ctx(ctx).Where(s.Columns().Name, name).Data(out).Update(); err != nil {
		return errs.NewOperateDBError(ctx, s.Table(), err)
	}

5. What did you expect to see?

  • Expect the condition only has the filed "name" which i set when I select with the po.SystemRole struct.
  • Expect to update the filed Type when I update with the po.SystemRole struct.

6. What did you see instead?

  • Actually the condition has all the fields of po.SystemRole.
  • Actually it update all the filed and set other fields to empty value.
@gqcn gqcn added bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version. labels Dec 18, 2023
gqcn added a commit that referenced this issue Dec 18, 2023
gqcn added a commit that referenced this issue Dec 18, 2023
@gqcn gqcn closed this as completed Dec 18, 2023
@zhangyuyu zhangyuyu changed the title 'Omitempty' in orm tag is no longer take effect when select/update using struct 'Omitempty' in orm tag is no longer take effect when select/update/insert using struct Dec 19, 2023
gqcn added a commit that referenced this issue Dec 19, 2023
gqcn added a commit that referenced this issue Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version.
Projects
None yet
Development

No branches or pull requests

2 participants