Skip to content
New issue

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

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

Already on GitHub? # to your account

fix : update miss where's condition when primary key use "<-:create" tag #4738

Merged
merged 2 commits into from Oct 8, 2021
Merged

fix : update miss where's condition when primary key use "<-:create" tag #4738

merged 2 commits into from Oct 8, 2021

Conversation

ghost
Copy link

@ghost ghost commented Sep 30, 2021

  • [] Do only one thing
  • [] Non breaking API changes
  • [] Tested

What did this pull request do?

fix:update miss where condition for #4734

when use update and primary key field use <-:create tag , maybe result in error.

User Case Description

Demo code:

//model.go
type User struct {
	ID   uint   `gorm:"column:id;<-:create"`
	Name string `gorm:"column:name"`
}

//dal.go
user := model.User{ID: 1, Name: "king"}
tx.Debug().Save(&user)
if tx.Error != nil {
	fmt.Printf("Failed, got error: %v \n", tx.Error)
}

Run result:

[0.135ms] [rows:0] UPDATE `users` SET `name`="king"
Failed, got error: WHERE conditions required 

Except result:

[0.172ms] [rows:0] UPDATE `users` SET `name`="king" WHERE `id` = 1

@ghost ghost added go Pull requests that update Go code and removed go Pull requests that update Go code labels Sep 30, 2021
@ghost ghost changed the title fix : update miss where's condition when use "<-:create" tag fix : update miss where's condition when primary key use "<-:create" tag Sep 30, 2021
@jinzhu jinzhu merged commit b46e2af into go-gorm:master Oct 8, 2021
@jinzhu
Copy link
Member

jinzhu commented Oct 8, 2021

thank you for your PR.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants