Check if value is struct before check Field

This commit is contained in:
Jinzhu 2014-03-11 10:08:16 +08:00
parent 24d527670b
commit 1086009fce
2 changed files with 3 additions and 2 deletions

View File

@ -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 {

View File

@ -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