From 940da051a756e425d7069a51eec412835cb6bbb1 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Tue, 23 Feb 2021 19:35:20 +0800 Subject: [PATCH] Skip nested associations when create data with Select, close #4108 --- callbacks/associations.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/callbacks/associations.go b/callbacks/associations.go index 28c769e7..dc84e137 100644 --- a/callbacks/associations.go +++ b/callbacks/associations.go @@ -349,8 +349,6 @@ func saveAssociations(db *gorm.DB, rel *schema.Relationship, values interface{}, columnName := "" if strings.HasPrefix(name, refName) { columnName = strings.TrimPrefix(name, refName) - } else if strings.HasPrefix(name, clause.Associations) { - columnName = name } if columnName != "" { @@ -374,6 +372,8 @@ func saveAssociations(db *gorm.DB, rel *schema.Relationship, values interface{}, if len(selects) > 0 { tx = tx.Select(selects) + } else if len(selectColumns) > 0 && len(omits) == 0 { + tx = tx.Omit(clause.Associations) } if len(omits) > 0 {