@@ -32,7 +32,6 @@ type Column struct {
32
32
IsDeleted bool
33
33
IsCascade bool
34
34
IsVersion bool
35
- fieldPath []string
36
35
DefaultIsEmpty bool
37
36
EnumOptions map [string ]int
38
37
SetOptions map [string ]int
@@ -59,7 +58,6 @@ func NewColumn(name, fieldName string, sqlType SQLType, len1, len2 int, nullable
59
58
IsDeleted : false ,
60
59
IsCascade : false ,
61
60
IsVersion : false ,
62
- fieldPath : nil ,
63
61
DefaultIsEmpty : false ,
64
62
EnumOptions : make (map [string ]int ),
65
63
}
@@ -121,32 +119,30 @@ func (col *Column) ValueOf(bean interface{}) (*reflect.Value, error) {
121
119
122
120
func (col * Column ) ValueOfV (dataStruct * reflect.Value ) (* reflect.Value , error ) {
123
121
var fieldValue reflect.Value
124
- if col .fieldPath == nil {
125
- col .fieldPath = strings .Split (col .FieldName , "." )
126
- }
122
+ fieldPath := strings .Split (col .FieldName , "." )
127
123
128
124
if dataStruct .Type ().Kind () == reflect .Map {
129
- keyValue := reflect .ValueOf (col . fieldPath [len (col . fieldPath )- 1 ])
125
+ keyValue := reflect .ValueOf (fieldPath [len (fieldPath )- 1 ])
130
126
fieldValue = dataStruct .MapIndex (keyValue )
131
127
return & fieldValue , nil
132
128
} else if dataStruct .Type ().Kind () == reflect .Interface {
133
129
structValue := reflect .ValueOf (dataStruct .Interface ())
134
130
dataStruct = & structValue
135
131
}
136
132
137
- level := len (col . fieldPath )
138
- fieldValue = dataStruct .FieldByName (col . fieldPath [0 ])
133
+ level := len (fieldPath )
134
+ fieldValue = dataStruct .FieldByName (fieldPath [0 ])
139
135
for i := 0 ; i < level - 1 ; i ++ {
140
136
if ! fieldValue .IsValid () {
141
137
break
142
138
}
143
139
if fieldValue .Kind () == reflect .Struct {
144
- fieldValue = fieldValue .FieldByName (col . fieldPath [i + 1 ])
140
+ fieldValue = fieldValue .FieldByName (fieldPath [i + 1 ])
145
141
} else if fieldValue .Kind () == reflect .Ptr {
146
142
if fieldValue .IsNil () {
147
143
fieldValue .Set (reflect .New (fieldValue .Type ().Elem ()))
148
144
}
149
- fieldValue = fieldValue .Elem ().FieldByName (col . fieldPath [i + 1 ])
145
+ fieldValue = fieldValue .Elem ().FieldByName (fieldPath [i + 1 ])
150
146
} else {
151
147
return nil , fmt .Errorf ("field %v is not valid" , col .FieldName )
152
148
}
0 commit comments