diff --git a/clause/where.go b/clause/where.go index 46d0b319..3db8a3d3 100644 --- a/clause/where.go +++ b/clause/where.go @@ -21,11 +21,11 @@ func (where Where) Name() string { // Build build where clause func (where Where) Build(builder Builder) { - if len(where.Exprs) == 1 { - if andCondition, ok := where.Exprs[0].(AndConditions); ok { - where.Exprs = andCondition.Exprs - } - } + if len(where.Exprs) == 1 { + if andCondition, ok := where.Exprs[0].(AndConditions); ok { + where.Exprs = andCondition.Exprs + } + } // Switch position if the first query expression is a single Or condition for idx, expr := range where.Exprs { @@ -153,11 +153,6 @@ func Not(exprs ...Expression) Expression { if len(exprs) == 0 { return nil } - if len(exprs) == 1 { - if andCondition, ok := exprs[0].(AndConditions); ok { - exprs = andCondition.Exprs - } - } return NotConditions{Exprs: exprs} } diff --git a/clause/where_test.go b/clause/where_test.go index aa9d06eb..28475a5c 100644 --- a/clause/where_test.go +++ b/clause/where_test.go @@ -105,6 +105,13 @@ func TestWhere(t *testing.T) { "SELECT * FROM `users` WHERE (`users`.`id` <> ? AND NOT `score` <= ?)", []interface{}{"1", 100}, }, + { + []clause.Interface{clause.Select{}, clause.From{}, clause.Where{ + Exprs: []clause.Expression{clause.Not(clause.And(clause.Eq{Column: clause.PrimaryColumn, Value: "1"}, clause.Expr{SQL: "`score` <= ?", Vars: []interface{}{100}, WithoutParentheses: false}))}, + }}, + "SELECT * FROM `users` WHERE NOT (`users`.`id` = ? AND `score` <= ?)", + []interface{}{"1", 100}, + }, } for idx, result := range results {