forked from mirror/gorm
Scan value into ignored fields if there is no ambiguity
This commit is contained in:
parent
8ee49893d1
commit
341703ed5d
2
field.go
2
field.go
|
@ -62,12 +62,14 @@ func (scope *Scope) Fields() map[string]*Field {
|
|||
indirectValue := scope.IndirectValue()
|
||||
isStruct := indirectValue.Kind() == reflect.Struct
|
||||
for _, structField := range modelStruct.StructFields {
|
||||
if field, ok := fields[structField.DBName]; !ok || field.IsIgnored {
|
||||
if isStruct {
|
||||
fields[structField.DBName] = getField(indirectValue, structField)
|
||||
} else {
|
||||
fields[structField.DBName] = &Field{StructField: structField, IsBlank: true}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if modelStruct.cached {
|
||||
scope.fields = fields
|
||||
|
|
|
@ -149,7 +149,8 @@ func (scope *Scope) GetModelStruct() *ModelStruct {
|
|||
|
||||
if fieldStruct.Tag.Get("sql") == "-" {
|
||||
field.IsIgnored = true
|
||||
} else {
|
||||
}
|
||||
|
||||
sqlSettings := parseTagSetting(field.Tag.Get("sql"))
|
||||
gormSettings := parseTagSetting(field.Tag.Get("gorm"))
|
||||
if _, ok := gormSettings["PRIMARY_KEY"]; ok {
|
||||
|
@ -166,7 +167,7 @@ func (scope *Scope) GetModelStruct() *ModelStruct {
|
|||
} else {
|
||||
field.DBName = ToDBName(fieldStruct.Name)
|
||||
}
|
||||
}
|
||||
|
||||
fields = append(fields, field)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue