diff --git a/finisher_api.go b/finisher_api.go index 39d9fca3..032a70fc 100644 --- a/finisher_api.go +++ b/finisher_api.go @@ -120,8 +120,13 @@ func (db *DB) First(dest interface{}, conds ...interface{}) (tx *DB) { Column: clause.Column{Table: clause.CurrentTable, Name: clause.PrimaryKey}, }) if len(conds) > 0 { - if exprs := tx.Statement.BuildCondition(conds[0], conds[1:]...); len(exprs) > 0 { - tx.Statement.AddClause(clause.Where{Exprs: exprs}) + if len(conds) == 1 { + cond := []clause.Expression{clause.IN{Column: clause.PrimaryColumn, Values: []interface{}{conds[0]}}} + tx.Statement.AddClause(clause.Where{Exprs: cond}) + } else { + if exprs := tx.Statement.BuildCondition(conds[0], conds[1:]...); len(exprs) > 0 { + tx.Statement.AddClause(clause.Where{Exprs: exprs}) + } } } tx.Statement.RaiseErrorOnNotFound = true @@ -427,8 +432,13 @@ func (db *DB) UpdateColumns(values interface{}) (tx *DB) { func (db *DB) Delete(value interface{}, conds ...interface{}) (tx *DB) { tx = db.getInstance() if len(conds) > 0 { - if exprs := tx.Statement.BuildCondition(conds[0], conds[1:]...); len(exprs) > 0 { - tx.Statement.AddClause(clause.Where{Exprs: exprs}) + if len(conds) == 1 { + cond := []clause.Expression{clause.IN{Column: clause.PrimaryColumn, Values: []interface{}{conds[0]}}} + tx.Statement.AddClause(clause.Where{Exprs: cond}) + } else { + if exprs := tx.Statement.BuildCondition(conds[0], conds[1:]...); len(exprs) > 0 { + tx.Statement.AddClause(clause.Where{Exprs: exprs}) + } } } tx.Statement.Dest = value diff --git a/statement.go b/statement.go index ad0ca9b0..b99648fa 100644 --- a/statement.go +++ b/statement.go @@ -287,11 +287,6 @@ func (stmt *Statement) BuildCondition(query interface{}, args ...interface{}) [] return nil } - if len(args) == 0 && (!strings.Contains(s, "?") && !strings.Contains(s, "@")) { - // The primary key type is not int, but string or uuid (#5984) - return []clause.Expression{clause.IN{Column: clause.PrimaryColumn, Values: []interface{}{s}}} - } - if len(args) == 0 || (len(args) > 0 && strings.Contains(s, "?")) { // looks like a where condition return []clause.Expression{clause.Expr{SQL: s, Vars: args}}