forked from mirror/gorm
Optimize: code logic db.scanIntoStruct() (#5633)
This commit is contained in:
parent
d71caef7d9
commit
f78f635fae
8
scan.go
8
scan.go
|
@ -66,9 +66,12 @@ func (db *DB) scanIntoStruct(rows Rows, reflectValue reflect.Value, values []int
|
||||||
db.RowsAffected++
|
db.RowsAffected++
|
||||||
db.AddError(rows.Scan(values...))
|
db.AddError(rows.Scan(values...))
|
||||||
|
|
||||||
joinedSchemaMap := make(map[*schema.Field]interface{}, 0)
|
joinedSchemaMap := make(map[*schema.Field]interface{})
|
||||||
for idx, field := range fields {
|
for idx, field := range fields {
|
||||||
if field != nil {
|
if field == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if len(joinFields) == 0 || joinFields[idx][0] == nil {
|
if len(joinFields) == 0 || joinFields[idx][0] == nil {
|
||||||
db.AddError(field.Set(db.Statement.Context, reflectValue, values[idx]))
|
db.AddError(field.Set(db.Statement.Context, reflectValue, values[idx]))
|
||||||
} else {
|
} else {
|
||||||
|
@ -90,7 +93,6 @@ func (db *DB) scanIntoStruct(rows Rows, reflectValue reflect.Value, values []int
|
||||||
// release data to pool
|
// release data to pool
|
||||||
field.NewValuePool.Put(values[idx])
|
field.NewValuePool.Put(values[idx])
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScanMode scan data mode
|
// ScanMode scan data mode
|
||||||
|
|
Loading…
Reference in New Issue