From 697839e94dc11602cf7b9cdae9069974a3389dab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=A0=87?= Date: Mon, 16 Jan 2023 14:02:32 +0800 Subject: [PATCH] fix(statement): The primary key type is not int, but string or uuid (#5984) --- finisher_api.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/finisher_api.go b/finisher_api.go index 032a70fc..ec5b6946 100644 --- a/finisher_api.go +++ b/finisher_api.go @@ -120,8 +120,9 @@ func (db *DB) First(dest interface{}, conds ...interface{}) (tx *DB) { Column: clause.Column{Table: clause.CurrentTable, Name: clause.PrimaryKey}, }) if len(conds) > 0 { - if len(conds) == 1 { - cond := []clause.Expression{clause.IN{Column: clause.PrimaryColumn, Values: []interface{}{conds[0]}}} + pkValue, ok := conds[0].(string) + if len(conds) == 1 && ok { + cond := []clause.Expression{clause.IN{Column: clause.PrimaryColumn, Values: []interface{}{pkValue}}} tx.Statement.AddClause(clause.Where{Exprs: cond}) } else { if exprs := tx.Statement.BuildCondition(conds[0], conds[1:]...); len(exprs) > 0 { @@ -432,8 +433,9 @@ 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 len(conds) == 1 { - cond := []clause.Expression{clause.IN{Column: clause.PrimaryColumn, Values: []interface{}{conds[0]}}} + pkValue, ok := conds[0].(string) + if len(conds) == 1 && ok { + cond := []clause.Expression{clause.IN{Column: clause.PrimaryColumn, Values: []interface{}{pkValue}}} tx.Statement.AddClause(clause.Where{Exprs: cond}) } else { if exprs := tx.Statement.BuildCondition(conds[0], conds[1:]...); len(exprs) > 0 {