Your Question

Hi Jinzhu,

i have a quick technical question for you about the gorm.ScanOnConflictDoNothing mode on the sqlserver/create.go file.

on-conflict-do-nothing

This mode gets passed to this part of gorm/scan.go

gorm-scan

What is the purpouse of this mode?

Currently it has a very dangerous side effect: if a field with a default value is valued in the model when Creating, gorm skips all the other columns with a database generated value, including the primary key.

This means that the nested items get inserted with the parent key of 0 (or null if it is a pointer).

In sqlserver/create.go removing gorm.ScanOnConflictDoNothing and keeping only gorm.ScanUpdate solves this issue for me.

The document you expected this should be explained

Probably none as it a technical question?

Expected answer

What is the purpouse of the gorm.ScanOnConflictDoNothing mode? Which is the correct way to fix this while continuing to use fields with default values? Is there some other way or method that i'm missing?

Thank you for your time.

Comment From: github-actions[bot]

This issue has been automatically marked as stale because it has been open 360 days with no activity. Remove stale label or comment or this will be closed in 180 days