From 9f533950a2864277d4210a355531abc49da0246b Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Thu, 28 Oct 2021 17:12:31 +0800 Subject: [PATCH] Add dest value if current size equal zero --- scan.go | 3 ++- tests/go.mod | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/scan.go b/scan.go index 360ed8b9..119049c6 100644 --- a/scan.go +++ b/scan.go @@ -225,7 +225,8 @@ func Scan(rows *sql.Rows, db *DB, mode ScanMode) { case reflect.Slice, reflect.Array: 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)) } diff --git a/tests/go.mod b/tests/go.mod index ab3ef898..52781a8b 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -6,7 +6,7 @@ require ( github.com/google/uuid v1.3.0 github.com/jinzhu/now v1.1.2 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/sqlite v1.2.2 gorm.io/driver/sqlserver v1.1.2