mirror of https://github.com/go-gorm/gorm.git
Replace FullTable with TableExpr
This commit is contained in:
parent
e77156980c
commit
de764d9e3d
|
@ -47,7 +47,7 @@ var tableRegexp = regexp.MustCompile(`(?i).+ AS (\w+)\s*$`)
|
||||||
func (db *DB) Table(name string) (tx *DB) {
|
func (db *DB) Table(name string) (tx *DB) {
|
||||||
tx = db.getInstance()
|
tx = db.getInstance()
|
||||||
if strings.Contains(name, " ") {
|
if strings.Contains(name, " ") {
|
||||||
tx.Statement.FullTable = name
|
tx.Statement.TableExpr = &clause.Expr{SQL: name}
|
||||||
if results := tableRegexp.FindStringSubmatch(name); len(results) == 2 {
|
if results := tableRegexp.FindStringSubmatch(name); len(results) == 2 {
|
||||||
tx.Statement.Table = results[1]
|
tx.Statement.Table = results[1]
|
||||||
return
|
return
|
||||||
|
|
|
@ -19,7 +19,7 @@ import (
|
||||||
// Statement statement
|
// Statement statement
|
||||||
type Statement struct {
|
type Statement struct {
|
||||||
*DB
|
*DB
|
||||||
FullTable string
|
TableExpr *clause.Expr
|
||||||
Table string
|
Table string
|
||||||
Model interface{}
|
Model interface{}
|
||||||
Unscoped bool
|
Unscoped bool
|
||||||
|
@ -69,8 +69,8 @@ func (stmt *Statement) QuoteTo(writer clause.Writer, field interface{}) {
|
||||||
switch v := field.(type) {
|
switch v := field.(type) {
|
||||||
case clause.Table:
|
case clause.Table:
|
||||||
if v.Name == clause.CurrentTable {
|
if v.Name == clause.CurrentTable {
|
||||||
if stmt.FullTable != "" {
|
if stmt.TableExpr != nil {
|
||||||
writer.WriteString(stmt.FullTable)
|
stmt.TableExpr.Build(stmt)
|
||||||
} else {
|
} else {
|
||||||
stmt.DB.Dialector.QuoteTo(writer, stmt.Table)
|
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) {
|
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 == "" {
|
if stmt.Schema, err = schema.Parse(value, stmt.DB.cacheStore, stmt.DB.NamingStrategy); err == nil && stmt.Table == "" {
|
||||||
stmt.Table = stmt.Schema.Table
|
stmt.Table = stmt.Schema.Table
|
||||||
stmt.FullTable = stmt.Schema.Table
|
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue