Skip nested associations when create data with Select, close #4108

This commit is contained in:
Jinzhu 2021-02-23 19:35:20 +08:00
parent 79225bfe48
commit 940da051a7
1 changed files with 2 additions and 2 deletions

View File

@ -349,8 +349,6 @@ func saveAssociations(db *gorm.DB, rel *schema.Relationship, values interface{},
columnName := "" columnName := ""
if strings.HasPrefix(name, refName) { if strings.HasPrefix(name, refName) {
columnName = strings.TrimPrefix(name, refName) columnName = strings.TrimPrefix(name, refName)
} else if strings.HasPrefix(name, clause.Associations) {
columnName = name
} }
if columnName != "" { if columnName != "" {
@ -374,6 +372,8 @@ func saveAssociations(db *gorm.DB, rel *schema.Relationship, values interface{},
if len(selects) > 0 { if len(selects) > 0 {
tx = tx.Select(selects) tx = tx.Select(selects)
} else if len(selectColumns) > 0 && len(omits) == 0 {
tx = tx.Omit(clause.Associations)
} }
if len(omits) > 0 { if len(omits) > 0 {