mirror of https://github.com/go-gorm/gorm.git
Check if value is struct before check Field
This commit is contained in:
parent
24d527670b
commit
1086009fce
|
@ -41,6 +41,7 @@ type User struct {
|
||||||
Latitude float64
|
Latitude float64
|
||||||
PasswordHash []byte
|
PasswordHash []byte
|
||||||
IgnoreMe int64 `sql:"-"`
|
IgnoreMe int64 `sql:"-"`
|
||||||
|
IgnoreStringSlice []string `sql:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreditCard struct {
|
type CreditCard struct {
|
||||||
|
|
2
scope.go
2
scope.go
|
@ -252,7 +252,7 @@ func (scope *Scope) Fields() []*Field {
|
||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
typ = typ.Elem()
|
typ = typ.Elem()
|
||||||
|
|
||||||
if _, ok := field.Value.([]byte); !ok {
|
if typ.Kind() == reflect.Struct {
|
||||||
foreignKey := scopeTyp.Name() + "Id"
|
foreignKey := scopeTyp.Name() + "Id"
|
||||||
if reflect.New(typ).Elem().FieldByName(foreignKey).IsValid() {
|
if reflect.New(typ).Elem().FieldByName(foreignKey).IsValid() {
|
||||||
field.ForeignKey = foreignKey
|
field.ForeignKey = foreignKey
|
||||||
|
|
Loading…
Reference in New Issue