Adjust ToStringKey use unpack params, fix pass []any as any in variadic function (#5500)

* fix pass []any as any in variadic function

* add .vscode to gitignore
This commit is contained in:
alingse
2022-07-14 20:05:22 +08:00
committed by GitHub
parent 4d40e34734
commit 099813bf11
3 changed files with 21 additions and 3 deletions
+2 -1
View File
@@ -3,4 +3,5 @@ documents
coverage.txt
_book
.idea
vendor
vendor
.vscode
+2 -2
View File
@@ -206,7 +206,7 @@ func SaveAfterAssociations(create bool) func(db *gorm.DB) {
}
}
cacheKey := utils.ToStringKey(relPrimaryValues)
cacheKey := utils.ToStringKey(relPrimaryValues...)
if len(relPrimaryValues) != len(rel.FieldSchema.PrimaryFields) || !identityMap[cacheKey] {
identityMap[cacheKey] = true
if isPtr {
@@ -292,7 +292,7 @@ func SaveAfterAssociations(create bool) func(db *gorm.DB) {
}
}
cacheKey := utils.ToStringKey(relPrimaryValues)
cacheKey := utils.ToStringKey(relPrimaryValues...)
if len(relPrimaryValues) != len(rel.FieldSchema.PrimaryFields) || !identityMap[cacheKey] {
identityMap[cacheKey] = true
distinctElems = reflect.Append(distinctElems, elem)
+17
View File
@@ -12,3 +12,20 @@ func TestIsValidDBNameChar(t *testing.T) {
}
}
}
func TestToStringKey(t *testing.T) {
cases := []struct {
values []interface{}
key string
}{
{[]interface{}{"a"}, "a"},
{[]interface{}{1, 2, 3}, "1_2_3"},
{[]interface{}{[]interface{}{1, 2, 3}}, "[1 2 3]"},
{[]interface{}{[]interface{}{"1", "2", "3"}}, "[1 2 3]"},
}
for _, c := range cases {
if key := ToStringKey(c.values...); key != c.key {
t.Errorf("%v: expected %v, got %v", c.values, c.key, key)
}
}
}