Add dest value if current size equal zero

This commit is contained in:
Jinzhu 2021-10-28 17:12:31 +08:00
parent e953880d19
commit 9f533950a2
2 changed files with 3 additions and 2 deletions

View File

@ -225,7 +225,8 @@ func Scan(rows *sql.Rows, db *DB, mode ScanMode) {
case reflect.Slice, reflect.Array: case reflect.Slice, reflect.Array:
var elem reflect.Value var elem reflect.Value
if !update && reflectValue.Len() != 0 { if !update || reflectValue.Len() == 0 {
update = false
db.Statement.ReflectValue.Set(reflect.MakeSlice(reflectValue.Type(), 0, 20)) db.Statement.ReflectValue.Set(reflect.MakeSlice(reflectValue.Type(), 0, 20))
} }

View File

@ -6,7 +6,7 @@ require (
github.com/google/uuid v1.3.0 github.com/google/uuid v1.3.0
github.com/jinzhu/now v1.1.2 github.com/jinzhu/now v1.1.2
github.com/lib/pq v1.10.3 github.com/lib/pq v1.10.3
gorm.io/driver/mysql v1.1.2 gorm.io/driver/mysql v1.1.3
gorm.io/driver/postgres v1.2.1 gorm.io/driver/postgres v1.2.1
gorm.io/driver/sqlite v1.2.2 gorm.io/driver/sqlite v1.2.2
gorm.io/driver/sqlserver v1.1.2 gorm.io/driver/sqlserver v1.1.2