From de764d9e3deb99d489e6538219fe5fbb12062e72 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Fri, 17 Jul 2020 21:19:11 +0800 Subject: [PATCH] Replace FullTable with TableExpr --- chainable_api.go | 2 +- statement.go | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/chainable_api.go b/chainable_api.go index 7c352268..fe11e474 100644 --- a/chainable_api.go +++ b/chainable_api.go @@ -47,7 +47,7 @@ var tableRegexp = regexp.MustCompile(`(?i).+ AS (\w+)\s*$`) func (db *DB) Table(name string) (tx *DB) { tx = db.getInstance() if strings.Contains(name, " ") { - tx.Statement.FullTable = name + tx.Statement.TableExpr = &clause.Expr{SQL: name} if results := tableRegexp.FindStringSubmatch(name); len(results) == 2 { tx.Statement.Table = results[1] return diff --git a/statement.go b/statement.go index 3a2344ae..6641aed8 100644 --- a/statement.go +++ b/statement.go @@ -19,7 +19,7 @@ import ( // Statement statement type Statement struct { *DB - FullTable string + TableExpr *clause.Expr Table string Model interface{} Unscoped bool @@ -69,8 +69,8 @@ func (stmt *Statement) QuoteTo(writer clause.Writer, field interface{}) { switch v := field.(type) { case clause.Table: if v.Name == clause.CurrentTable { - if stmt.FullTable != "" { - writer.WriteString(stmt.FullTable) + if stmt.TableExpr != nil { + stmt.TableExpr.Build(stmt) } else { stmt.DB.Dialector.QuoteTo(writer, stmt.Table) } @@ -378,7 +378,6 @@ func (stmt *Statement) Build(clauses ...string) { func (stmt *Statement) Parse(value interface{}) (err error) { if stmt.Schema, err = schema.Parse(value, stmt.DB.cacheStore, stmt.DB.NamingStrategy); err == nil && stmt.Table == "" { stmt.Table = stmt.Schema.Table - stmt.FullTable = stmt.Schema.Table } return err }