From 540b47571a2c74134c2a8eb02d5a8ef70b0bf8d6 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Fri, 18 Mar 2022 20:57:33 +0800 Subject: [PATCH] Fix update select clause with before/after expressions, close #5164 --- chainable_api.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/chainable_api.go b/chainable_api.go index 38ad5cde..68b4d1aa 100644 --- a/chainable_api.go +++ b/chainable_api.go @@ -93,7 +93,11 @@ func (db *DB) Select(query interface{}, args ...interface{}) (tx *DB) { return } } - delete(tx.Statement.Clauses, "SELECT") + + if clause, ok := tx.Statement.Clauses["SELECT"]; ok { + clause.Expression = nil + tx.Statement.Clauses["SELECT"] = clause + } case string: if strings.Count(v, "?") >= len(args) && len(args) > 0 { tx.Statement.AddClause(clause.Select{ @@ -123,7 +127,10 @@ func (db *DB) Select(query interface{}, args ...interface{}) (tx *DB) { } } - delete(tx.Statement.Clauses, "SELECT") + if clause, ok := tx.Statement.Clauses["SELECT"]; ok { + clause.Expression = nil + tx.Statement.Clauses["SELECT"] = clause + } } default: tx.AddError(fmt.Errorf("unsupported select args %v %v", query, args))