forked from mirror/gorm
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:
parent
4d40e34734
commit
099813bf11
|
@ -4,3 +4,4 @@ coverage.txt
|
||||||
_book
|
_book
|
||||||
.idea
|
.idea
|
||||||
vendor
|
vendor
|
||||||
|
.vscode
|
||||||
|
|
|
@ -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] {
|
if len(relPrimaryValues) != len(rel.FieldSchema.PrimaryFields) || !identityMap[cacheKey] {
|
||||||
identityMap[cacheKey] = true
|
identityMap[cacheKey] = true
|
||||||
if isPtr {
|
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] {
|
if len(relPrimaryValues) != len(rel.FieldSchema.PrimaryFields) || !identityMap[cacheKey] {
|
||||||
identityMap[cacheKey] = true
|
identityMap[cacheKey] = true
|
||||||
distinctElems = reflect.Append(distinctElems, elem)
|
distinctElems = reflect.Append(distinctElems, elem)
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue