related issues
5126 gorm最新版Has Many只写入了关联数组的第一个
4796 pgsql: ON CONFLICT DO UPDATE command cannot affect row a second time
4890 Regression in 1.22.4: Storing int PKs with value zero
I think it should be
cacheKey := utils.ToStringKey(relPrimaryValues...)
not https://github.com/go-gorm/gorm/blob/f7b52bb649ba803ec149a06fec9e9da7b311d36e/callbacks/associations.go#L209
and when there's no primary keys, we should append elems
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)
} else {
elems = reflect.Append(elems, elem.Addr())
}
}
not https://github.com/go-gorm/gorm/blob/f7b52bb649ba803ec149a06fec9e9da7b311d36e/callbacks/associations.go#L210
Comment From: kaisawind
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: kaisawind
https://github.com/go-gorm/gorm/pull/5221#issuecomment-1086824732
i give it up.