diff --git a/callbacks/associations.go b/callbacks/associations.go index fd3141cf..2107a06a 100644 --- a/callbacks/associations.go +++ b/callbacks/associations.go @@ -206,8 +206,8 @@ func SaveAfterAssociations(create bool) func(db *gorm.DB) { } } - cacheKey := utils.ToStringKey(relPrimaryValues) - if len(relPrimaryValues) != len(rel.FieldSchema.PrimaryFields) || !identityMap[cacheKey] { + cacheKey := utils.ToStringKey(relPrimaryValues...) + if len(relPrimaryValues) == 0 || len(relPrimaryValues) != len(rel.FieldSchema.PrimaryFields) || !identityMap[cacheKey] { identityMap[cacheKey] = true if isPtr { elems = reflect.Append(elems, elem)