Skip to content

Commit

Permalink
Add dest value if current size equal zero
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Oct 28, 2021
1 parent e953880 commit 9f53395
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
2 changes: 1 addition & 1 deletion tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9f53395

Please sign in to comment.