From 42999e980916d8a5ee257eb116a351bceace691f Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Thu, 4 Mar 2021 18:28:32 +0800 Subject: [PATCH] Fix overwrite preloading associations, close #4134 --- callbacks/query.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/callbacks/query.go b/callbacks/query.go index 5a97e1ad..658216df 100644 --- a/callbacks/query.go +++ b/callbacks/query.go @@ -172,7 +172,9 @@ func Preload(db *gorm.DB) { if name == clause.Associations { for _, rel := range db.Statement.Schema.Relationships.Relations { if rel.Schema == db.Statement.Schema { - preloadMap[rel.Name] = map[string][]interface{}{} + if _, ok := preloadMap[rel.Name]; !ok { + preloadMap[rel.Name] = map[string][]interface{}{} + } } } } else {