Merge cb7ffae59c
into fad61020e8
This commit is contained in:
commit
013c963906
16
engine.go
16
engine.go
|
@ -771,6 +771,22 @@ func (engine *Engine) mapType(v reflect.Value) *core.Table {
|
|||
if tags[0] == "-" {
|
||||
continue
|
||||
}
|
||||
|
||||
// by hzm
|
||||
if strings.ToUpper(tags[0]) == "INHERITS" {
|
||||
engine.LogInfo(tags[0])
|
||||
if fieldValue.Kind() == reflect.Struct {
|
||||
// 保留为了Find()映射数据
|
||||
parentTable := engine.mapType(fieldValue)
|
||||
for _, col := range parentTable.Columns() {
|
||||
col.FieldName = fmt.Sprintf("%v.%v", t.Field(i).Name, col.FieldName)
|
||||
table.AddColumn(col)
|
||||
}
|
||||
table.AddInherit(engine.TableMapper.Obj2Table(fieldType.Name()))
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.ToUpper(tags[0]) == "EXTENDS" {
|
||||
if fieldValue.Kind() == reflect.Struct {
|
||||
parentTable := engine.mapType(fieldValue)
|
||||
|
|
|
@ -187,7 +187,7 @@ func reflect2value(rawValue *reflect.Value) (str string, err error) {
|
|||
//时间类型
|
||||
case reflect.Struct:
|
||||
if aa.ConvertibleTo(core.TimeType) {
|
||||
str = vv.Convert(core.TimeType).Interface().(time.Time).Format(time.RFC3339Nano)
|
||||
str = vv.Convert(core.TimeType).Interface().(time.Time).Format("2006-01-02 15:04:05")
|
||||
} else {
|
||||
err = fmt.Errorf("Unsupported struct type %v", vv.Type().Name())
|
||||
}
|
||||
|
|
10
statement.go
10
statement.go
|
@ -852,7 +852,15 @@ func (statement *Statement) Cols(columns ...string) *Statement {
|
|||
for _, nc := range newColumns {
|
||||
statement.columnMap[strings.ToLower(nc)] = true
|
||||
}
|
||||
statement.ColumnStr = statement.Engine.Quote(strings.Join(newColumns, statement.Engine.Quote(", ")))
|
||||
|
||||
// by hzm
|
||||
if len(newColumns) == 1 {
|
||||
statement.ColumnStr = newColumns[0]
|
||||
|
||||
} else {
|
||||
statement.ColumnStr = statement.Engine.Quote(strings.Join(newColumns, statement.Engine.Quote(", ")))
|
||||
}
|
||||
|
||||
if strings.Contains(statement.ColumnStr, ".") {
|
||||
statement.ColumnStr = strings.Replace(statement.ColumnStr, ".", statement.Engine.Quote("."), -1)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue