-
-
Notifications
You must be signed in to change notification settings - Fork 341
feat: add FieldLevelPermission in field options #774
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
Conversation
|
@qqxhb Yes, g := gen.NewGenerator(gen.Config{
Mode: gen.WithoutContext,
ModelPkgPath: modelsPath,
FieldWithIndexTag: true,
FieldWithTypeTag: true,
})
// ....
g.GenerateModelAs(table, db.Config.NamingStrategy.SchemaName(table), gen.FieldGORMTag("created_at", "->"))Result: type User struct {
CreatedAt time.Time `gorm:"->" json:"created_at"` // created time
}Expected results: type User struct {
CreatedAt time.Time `gorm:"->;column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3)" json:"created_at"` // created time
} |
|
I want to ensure that gen supports Field-Level Permission while automatically generating gorm tags, rather than writing all gorm tags manually. |
|
@BlackHole1 |
|
I don't quite understand "It is not universal", as far as I know,
|
哈哈 ,没问题。我想说的是,提供一个更换tag的option更通用,如果是加更换局部的,可能会导致option数量暴涨,每一个小点都可能要一个option |
Good idea。从这个方面来看,我们可以提供实现以下其中一个 API(可以讨论哪种方式会更好): 方案一// 定义
func FieldGORMTagHandler(func(columnName, gormTag string) string) model.FilterFieldOpt
// 使用
gen.FieldGORMTagHandler(func(columnName, gormTag string) string {
if (columnName == "created_at") {
return "->;" + gormTag
}
return gormTag
})方案二// 定义
func FieldGORMTagHandler(func(gormTag string) string, columnNames ...string) model.FilterFieldOpt
// 使用
gen.FieldGORMTagHandler(func(gormTag string) string {
return "->;" + gormTag
}, "created_at", "updated_at")
|
|
ping @qqxhb |
|
#784 gen.FieldGORMTag("created_at", func(tag field.GormTag) field.GormTag {//处理gorm tag
tag.Set("<-", "false") //加只读 tag
tag.Set("serialize","json")
//tag.Remove("type") //移除gorm的 type tag
return tag
}), |
What did this pull request do?
Support Field-Level Permission in generating the model.
User Case Description
The above MySQL code shows that
created_atandupdated_athave default values, andupdated_athas anon updatehook.This means that updates to these two fields do not need to be reflected in the project code, and we do not expect developers to write to these two fields.
If Field-Level Permission is not supported, some developers may accidentally fill in these two fields during the development process and the result will not be as expected.