Skip to content

Commit

Permalink
fix: tables lost when joins exists in from clause
Browse files Browse the repository at this point in the history
  • Loading branch information
chein-huang committed Apr 1, 2022
1 parent f7b52bb commit 95d00e6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion callbacks/query.go
Expand Up @@ -96,9 +96,11 @@ func BuildQuerySQL(db *gorm.DB) {
}

// inline joins
tables := []clause.Table{}
joins := []clause.Join{}
if fromClause, ok := db.Statement.Clauses["FROM"].Expression.(clause.From); ok {
joins = fromClause.Joins
tables = fromClause.Tables
}

if len(db.Statement.Joins) != 0 || len(joins) != 0 {
Expand Down Expand Up @@ -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
} else {
db.Statement.AddClauseIfNotExists(clause.From{})
Expand Down

0 comments on commit 95d00e6

Please sign in to comment.