From 56bdded0f851ef64b2008fda0dff4ef0854d1713 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Sun, 14 Jun 2020 11:46:17 +0800 Subject: [PATCH] Fix statement modifier support --- chainable_api.go | 2 ++ clause/clause.go | 2 +- statement.go | 9 ++++----- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/chainable_api.go b/chainable_api.go index 0be86e03..dbd783fd 100644 --- a/chainable_api.go +++ b/chainable_api.go @@ -27,6 +27,8 @@ func (db *DB) Clauses(conds ...clause.Expression) (tx *DB) { for _, cond := range conds { if c, ok := cond.(clause.Interface); ok { tx.Statement.AddClause(c) + } else if optimizer, ok := cond.(StatementModifier); ok { + optimizer.ModifyStatement(tx.Statement) } else { whereConds = append(whereConds, cond) } diff --git a/clause/clause.go b/clause/clause.go index b3e96332..64f08d14 100644 --- a/clause/clause.go +++ b/clause/clause.go @@ -48,7 +48,7 @@ func (c Clause) Build(builder Builder) { } if c.AfterNameExpression != nil { - c.BeforeExpression.Build(builder) + c.AfterNameExpression.Build(builder) builder.WriteByte(' ') } diff --git a/statement.go b/statement.go index e0e86019..720ef283 100644 --- a/statement.go +++ b/statement.go @@ -202,12 +202,11 @@ func (stmt *Statement) AddClause(v clause.Interface) { if optimizer, ok := v.(StatementModifier); ok { optimizer.ModifyStatement(stmt) } else { - c, ok := stmt.Clauses[v.Name()] - if !ok { - c.Name = v.Name() - } + name := v.Name() + c, _ := stmt.Clauses[name] + c.Name = name v.MergeClause(&c) - stmt.Clauses[v.Name()] = c + stmt.Clauses[name] = c } }