Skip to content

Commit

Permalink
fix: AfterQuery keep the original From Joins
Browse files Browse the repository at this point in the history
  • Loading branch information
贾一饼 authored and 贾一饼 committed May 17, 2024
1 parent 93e9d08 commit e0e6956
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion callbacks/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func AfterQuery(db *gorm.DB) {
// clear the joins after query because preload need it
if v, ok := db.Statement.Clauses["FROM"].Expression.(clause.From); ok {
fromClause := db.Statement.Clauses["FROM"]
fromClause.Expression = clause.From{Tables: v.Tables}
fromClause.Expression = clause.From{Tables: v.Tables, Joins: v.Joins[:len(v.Joins)-len(db.Statement.Joins)]} // keep the original From Joins
db.Statement.Clauses["FROM"] = fromClause
}
if db.Error == nil && db.Statement.Schema != nil && !db.Statement.SkipHooks && db.Statement.Schema.AfterFind && db.RowsAffected > 0 {
Expand Down

0 comments on commit e0e6956

Please sign in to comment.