From 95d00e6ff2668233f3eca98aa4917291e3d869bd Mon Sep 17 00:00:00 2001 From: huangcheng1 Date: Fri, 1 Apr 2022 16:30:27 +0800 Subject: [PATCH] fix: tables lost when joins exists in from clause --- callbacks/query.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/callbacks/query.go b/callbacks/query.go index 6eda52ef..748dc609 100644 --- a/callbacks/query.go +++ b/callbacks/query.go @@ -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 { @@ -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{})