From a9f54d53fbb4cfdda6a635369229379fb73bd694 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Mon, 16 Nov 2020 12:23:13 +0800 Subject: [PATCH] Don't preload when there are any error happened --- callbacks/query.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/callbacks/query.go b/callbacks/query.go index 8613e46d..92f711f5 100644 --- a/callbacks/query.go +++ b/callbacks/query.go @@ -206,7 +206,9 @@ func Preload(db *gorm.DB) { } } - preload(db, rels, db.Statement.Preloads[name]) + if db.Error == nil { + preload(db, rels, db.Statement.Preloads[name]) + } } } }