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

多对多创建的时候如何取消掉被关联表的ON DUPLICATE KEY UPDATE ? #7256

Open
liyuan1125 opened this issue Oct 25, 2024 · 1 comment
Assignees
Labels
type:question general questions

Comments

@liyuan1125
Copy link

Your Question

type (
	Languages struct {
		ID   uint   `json:"id"`
		Name string `json:"name"`
	}

	User struct {
		ID        uint         `json:"id"`
		Name      string       `json:"name"`
		Languages []*Languages `json:"languages"`
	}
)

user := &User{Name: "jinzhu", Languages: []*Languages{
		{ID:1},
		{ID:2},
	}}

	db.Create(user)
	db.Session(&gorm.Session{FullSaveAssociations: false}).Create(user)

以上会多一句:

INSERT INTO `languages ` (`name`,`id`) VALUES ('',1),('',2) ON DUPLICATE KEY UPDATE `id`=`id`

不能跳过吗?

@liyuan1125 liyuan1125 added the type:question general questions label Oct 25, 2024
@alex-guoba
Copy link

omit the field

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question general questions
Projects
None yet
Development

No branches or pull requests

3 participants