diff --git a/session.go b/session.go index d232d30d..67fedd70 100644 --- a/session.go +++ b/session.go @@ -710,20 +710,9 @@ func (session *Session) slice2Bean(scanResults []interface{}, allColum *AllColum buildAfterProcessors(session, bean) - tempMap := make(map[string]int) var pk schemas.PK for i, field := range allColum.Fields { - var idx int - var ok bool - - if idx, ok = tempMap[field.LowerFieldName]; !ok { - idx = 0 - } else { - idx++ - } - tempMap[field.LowerFieldName] = idx - - col, fieldValue, err := getField(dataStruct, table, field.FieldName, idx) + col, fieldValue, err := getField(dataStruct, table, field.FieldName, field.TempIndex) if _, ok := err.(ErrFieldIsNotExist); ok { continue } else if err != nil { diff --git a/session_find.go b/session_find.go index 483b4d71..e0b8d295 100644 --- a/session_find.go +++ b/session_find.go @@ -167,6 +167,7 @@ type QueryedField struct { FieldName string LowerFieldName string ColumnType *sql.ColumnType + TempIndex int } type AllColumn struct { @@ -190,6 +191,22 @@ func ParseQueryRows(fieldNames []string, types []*sql.ColumnType) *AllColumn { } allColumn.Fields = fields + + tempMap := make(map[string]int) + for _, field := range fields { + var idx int + var ok bool + + if idx, ok = tempMap[field.LowerFieldName]; !ok { + idx = 0 + } else { + idx++ + } + + tempMap[field.LowerFieldName] = idx + field.TempIndex = idx + } + return &allColumn }