Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update mysql.go #132

Closed
wants to merge 1 commit into from
Closed

Update mysql.go #132

wants to merge 1 commit into from

Conversation

hhniao
Copy link

@hhniao hhniao commented Sep 1, 2023

fixed go-gorm/gorm#6566
remove ON DUPLICATE KEY UPDATE statement by onConflict.DoNothing is true

remove ON DUPLICATE KEY UPDATE statement by onConflict.DoNothing is true
@hhniao hhniao mentioned this pull request Sep 1, 2023
3 tasks
@@ -200,6 +200,10 @@ func (dialector Dialector) ClauseBuilders() map[string]clause.ClauseBuilder {
c.Build(builder)
return
}
// onConflict DoNothing, remove ON DUPLICATE KEY UPDATE statement
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will returns an error after remove the on duplicate update?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

db.Session(&gorm.Session{FullSaveAssociations: true}).Clauses(clause.OnConflict{DoNothing: true}).Create(m)
当我明确指定 clause.OnConflict{DoNothing: true}
那么该报错报错, 而不是自动修正.
如果没有明确声明clause.OnConflict{DoNothing: true}, 那么自动添加on duplicate 语句是一种合理的方式.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When users specified DoNothing as true, we would expect users don't received any error when there are any duplicated record.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那你是希望在什么情况下报错呢? 在关于外键并没有任何可以报错的选项

@jinzhu jinzhu closed this Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

how can i remove ON DUPLICATE KEY UPDATE?
2 participants