mirror of https://github.com/go-gorm/gorm.git
fix: tables lost when joins exists in from clause
This commit is contained in:
parent
f7b52bb649
commit
95d00e6ff2
|
@ -96,9 +96,11 @@ func BuildQuerySQL(db *gorm.DB) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// inline joins
|
// inline joins
|
||||||
|
tables := []clause.Table{}
|
||||||
joins := []clause.Join{}
|
joins := []clause.Join{}
|
||||||
if fromClause, ok := db.Statement.Clauses["FROM"].Expression.(clause.From); ok {
|
if fromClause, ok := db.Statement.Clauses["FROM"].Expression.(clause.From); ok {
|
||||||
joins = fromClause.Joins
|
joins = fromClause.Joins
|
||||||
|
tables = fromClause.Tables
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(db.Statement.Joins) != 0 || len(joins) != 0 {
|
if len(db.Statement.Joins) != 0 || len(joins) != 0 {
|
||||||
|
@ -188,7 +190,7 @@ func BuildQuerySQL(db *gorm.DB) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
db.Statement.AddClause(clause.From{Joins: joins})
|
db.Statement.AddClause(clause.From{Tables: tables, Joins: joins})
|
||||||
db.Statement.Joins = nil
|
db.Statement.Joins = nil
|
||||||
} else {
|
} else {
|
||||||
db.Statement.AddClauseIfNotExists(clause.From{})
|
db.Statement.AddClauseIfNotExists(clause.From{})
|
||||||
|
|
Loading…
Reference in New Issue