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
|
@ -40,7 +40,8 @@ type User struct {
|
|||
CreditCard CreditCard
|
||||
Latitude float64
|
||||
PasswordHash []byte
|
||||
IgnoreMe int64 `sql:"-"`
|
||||
IgnoreMe int64 `sql:"-"`
|
||||
IgnoreStringSlice []string `sql:"-"`
|
||||
}
|
||||
|
||||
type CreditCard struct {
|
||||
|
|
2
scope.go
2
scope.go
|
@ -252,7 +252,7 @@ func (scope *Scope) Fields() []*Field {
|
|||
case reflect.Slice:
|
||||
typ = typ.Elem()
|
||||
|
||||
if _, ok := field.Value.([]byte); !ok {
|
||||
if typ.Kind() == reflect.Struct {
|
||||
foreignKey := scopeTyp.Name() + "Id"
|
||||
if reflect.New(typ).Elem().FieldByName(foreignKey).IsValid() {
|
||||
field.ForeignKey = foreignKey
|
||||
|
|
Loading…
Reference in New Issue