diff --git a/schema/field.go b/schema/field.go index 5dbc96f1..207fb1ad 100644 --- a/schema/field.go +++ b/schema/field.go @@ -341,6 +341,15 @@ func (schema *Schema) ParseField(fieldStruct reflect.StructField) *Field { } } + // placeholder; readonly without migration + + if _, ok := field.TagSettings["<->"]; ok { + field.Readable = true + field.Creatable = false + field.Updatable = false + field.IgnoreMigration = true + } + if _, ok := field.TagSettings["EMBEDDED"]; ok || (fieldStruct.Anonymous && !isValuer && (field.Creatable || field.Updatable || field.Readable)) { if reflect.Indirect(fieldValue).Kind() == reflect.Struct { var err error diff --git a/schema/field_test.go b/schema/field_test.go index 64f4a909..c1460080 100644 --- a/schema/field_test.go +++ b/schema/field_test.go @@ -235,6 +235,7 @@ type UserWithPermissionControl struct { Name5 string `gorm:"<-:update"` Name6 string `gorm:"<-:create,update"` Name7 string `gorm:"->:false;<-:create,update"` + Ref string `gorm:"<->"` } func TestParseFieldWithPermission(t *testing.T) { @@ -252,6 +253,7 @@ func TestParseFieldWithPermission(t *testing.T) { {Name: "Name5", DBName: "name5", BindNames: []string{"Name5"}, DataType: schema.String, Tag: `gorm:"<-:update"`, Creatable: false, Updatable: true, Readable: true}, {Name: "Name6", DBName: "name6", BindNames: []string{"Name6"}, DataType: schema.String, Tag: `gorm:"<-:create,update"`, Creatable: true, Updatable: true, Readable: true}, {Name: "Name7", DBName: "name7", BindNames: []string{"Name7"}, DataType: schema.String, Tag: `gorm:"->:false;<-:create,update"`, Creatable: true, Updatable: true, Readable: false}, + {Name: "Ref", DBName: "ref", BindNames: []string{"Ref"}, DataType: schema.String, Tag: `gorm:"<->"`, Creatable: false, Updatable: false, Readable: true, IgnoreMigration: true}, } for _, f := range fields {