add support for prt to extends struct & resolved #115

This commit is contained in:
Lunny Xiao 2014-05-08 13:25:43 +08:00
parent 49e38d65be
commit 4b94c7b784
1 changed files with 22 additions and 2 deletions

View File

@ -590,12 +590,32 @@ func (engine *Engine) mapType(v reflect.Value) *core.Table {
continue
}
if strings.ToUpper(tags[0]) == "EXTENDS" {
fieldValue = reflect.Indirect(fieldValue)
//fieldValue = reflect.Indirect(fieldValue)
//fmt.Println("----", fieldValue.Kind())
if fieldValue.Kind() == reflect.Struct {
//parentTable := mappingTable(fieldType, tableMapper, colMapper, dialect, tagId)
parentTable := engine.mapType(fieldValue)
for _, col := range parentTable.Columns() {
col.FieldName = fmt.Sprintf("%v.%v", fieldValue.Type().Name(), col.FieldName)
col.FieldName = fmt.Sprintf("%v.%v", t.Field(i).Name, col.FieldName)
//fmt.Println("---", col.FieldName)
table.AddColumn(col)
}
continue
} else if fieldValue.Kind() == reflect.Ptr {
f := fieldValue.Type().Elem()
if f.Kind() == reflect.Struct {
fieldValue = fieldValue.Elem()
if !fieldValue.IsValid() || fieldValue.IsNil() {
fieldValue = reflect.New(f).Elem()
}
//fmt.Println("00000", fieldValue)
}
parentTable := engine.mapType(fieldValue)
for _, col := range parentTable.Columns() {
col.FieldName = fmt.Sprintf("%v.%v", t.Field(i).Name, col.FieldName)
table.AddColumn(col)
}