diff --git a/helpers.go b/helpers.go index a31e922c..aadeb6dc 100644 --- a/helpers.go +++ b/helpers.go @@ -155,6 +155,17 @@ func isZero(k interface{}) bool { return false } +func isZeroValue(v reflect.Value) bool { + if isZero(v.Interface()) { + return true + } + switch v.Kind() { + case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice: + return v.IsNil() + } + return false +} + func isStructZero(v reflect.Value) bool { if !v.IsValid() { return true diff --git a/session_insert.go b/session_insert.go index 5f8f7e1e..c9859b7a 100644 --- a/session_insert.go +++ b/session_insert.go @@ -674,7 +674,7 @@ func (session *Session) genInsertColumns(bean interface{}) ([]string, []interfac // !evalphobia! set fieldValue as nil when column is nullable and zero-value if _, ok := getFlagForColumn(session.statement.nullableMap, col); ok { - if col.Nullable && isZero(fieldValue.Interface()) { + if col.Nullable && isZeroValue(fieldValue) { var nilValue *int fieldValue = reflect.ValueOf(nilValue) } diff --git a/session_update.go b/session_update.go index a26b15a6..18425ec3 100644 --- a/session_update.go +++ b/session_update.go @@ -517,7 +517,7 @@ func (session *Session) genUpdateColumns(bean interface{}) ([]string, []interfac // !evalphobia! set fieldValue as nil when column is nullable and zero-value if _, ok := getFlagForColumn(session.statement.nullableMap, col); ok { - if col.Nullable && isZero(fieldValue.Interface()) { + if col.Nullable && isZeroValue(fieldValue) { var nilValue *int fieldValue = reflect.ValueOf(nilValue) }