mirror of https://github.com/go-gorm/gorm.git
Fix call valuer interface when using nil value
This commit is contained in:
parent
92d5a959a0
commit
45e804dd3f
|
@ -368,7 +368,7 @@ func (like Like) NegationBuild(builder Builder) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func eqNil(value interface{}) bool {
|
func eqNil(value interface{}) bool {
|
||||||
if valuer, ok := value.(driver.Valuer); ok {
|
if valuer, ok := value.(driver.Valuer); ok && !eqNilReflect(valuer) {
|
||||||
value, _ = valuer.Value()
|
value, _ = valuer.Value()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -173,7 +173,12 @@ func (stmt *Statement) AddVar(writer clause.Writer, vars ...interface{}) {
|
||||||
case clause.Column, clause.Table:
|
case clause.Column, clause.Table:
|
||||||
stmt.QuoteTo(writer, v)
|
stmt.QuoteTo(writer, v)
|
||||||
case Valuer:
|
case Valuer:
|
||||||
stmt.AddVar(writer, v.GormValue(stmt.Context, stmt.DB))
|
reflectValue := reflect.ValueOf(v)
|
||||||
|
if reflectValue.Kind() == reflect.Ptr && reflectValue.IsNil() {
|
||||||
|
stmt.AddVar(writer, nil)
|
||||||
|
} else {
|
||||||
|
stmt.AddVar(writer, v.GormValue(stmt.Context, stmt.DB))
|
||||||
|
}
|
||||||
case clause.Expr:
|
case clause.Expr:
|
||||||
v.Build(stmt)
|
v.Build(stmt)
|
||||||
case *clause.Expr:
|
case *clause.Expr:
|
||||||
|
|
Loading…
Reference in New Issue