fixed bug

This commit is contained in:
Wenhui Shen 2016-03-13 16:28:18 +08:00
parent bb8c5c04d7
commit 54473a3e45
1 changed files with 8 additions and 12 deletions

View File

@ -967,23 +967,18 @@ func (engine *Engine) mapType(v reflect.Value) *core.Table {
continue continue
} }
if strings.ToUpper(tags[0]) == "EXTENDS" { if strings.ToUpper(tags[0]) == "EXTENDS" {
if fieldValue.Kind() == reflect.Struct { switch fieldValue.Kind() {
parentTable := engine.mapType(fieldValue) case reflect.Ptr:
for _, col := range parentTable.Columns() {
col.FieldName = fmt.Sprintf("%v.%v", t.Field(i).Name, col.FieldName)
table.AddColumn(col)
}
continue
} else if fieldValue.Kind() == reflect.Ptr {
f := fieldValue.Type().Elem() f := fieldValue.Type().Elem()
if f.Kind() == reflect.Struct { if f.Kind() == reflect.Struct {
fieldPtr := fieldValue
fieldValue = fieldValue.Elem() fieldValue = fieldValue.Elem()
if !fieldValue.IsValid() || fieldValue.IsNil() { if !fieldValue.IsValid() || fieldPtr.IsNil() {
fieldValue = reflect.New(f).Elem() fieldValue = reflect.New(f).Elem()
} }
} }
fallthrough
case reflect.Struct:
parentTable := engine.mapType(fieldValue) parentTable := engine.mapType(fieldValue)
for _, col := range parentTable.Columns() { for _, col := range parentTable.Columns() {
col.FieldName = fmt.Sprintf("%v.%v", t.Field(i).Name, col.FieldName) col.FieldName = fmt.Sprintf("%v.%v", t.Field(i).Name, col.FieldName)
@ -991,9 +986,10 @@ func (engine *Engine) mapType(v reflect.Value) *core.Table {
} }
continue continue
} default:
//TODO: warning //TODO: warning
} }
}
indexNames := make(map[string]int) indexNames := make(map[string]int)
var isIndex, isUnique bool var isIndex, isUnique bool