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

Model().Save() does not generate WHERE clause #3519

Closed
mwlazlo opened this issue Sep 24, 2020 · 4 comments
Closed

Model().Save() does not generate WHERE clause #3519

mwlazlo opened this issue Sep 24, 2020 · 4 comments
Assignees
Labels
type:with reproduction steps with reproduction steps

Comments

@mwlazlo
Copy link

mwlazlo commented Sep 24, 2020

GORM Playground Link

go-gorm/playground#154

Description

value := &Test{Value: "foo"}
db.Model(Test{}).Create(&value)
value.Value = "bar"
db.Model(Test{}).Save(&value)
--> Save: WHERE condition required

Bug, or no longer supported to use Model?

db.Save(&value) --> OK
@github-actions github-actions bot added type:missing reproduction steps missing reproduction steps type:with reproduction steps with reproduction steps and removed type:missing reproduction steps missing reproduction steps labels Sep 24, 2020
@jinzhu
Copy link
Member

jinzhu commented Sep 24, 2020

https://gorm.io/docs/v2_release_note.html#BlockGlobalUpdate

@jinzhu jinzhu closed this as completed Sep 24, 2020
@mwlazlo
Copy link
Author

mwlazlo commented Sep 24, 2020

@jinzhu The condition is generated without the .Model(),but you don't require a .Where() before a .Save() so I don't understand how this isn't a bug.

@mwlazlo
Copy link
Author

mwlazlo commented Sep 24, 2020

@jinzhu

	db.Debug().Model(Test{}).Save(&test)
Outputs
[0.284ms] [rows:0] UPDATE `tests` SET `id`=1,`value`="test"

	db.Debug().Save(&test)
Outputs
[0.525ms] [rows:0] UPDATE `tests` SET `value`="test" WHERE `id` = 1

@david0u0
Copy link

david0u0 commented Sep 28, 2020

Having same problem, wonder if there is a way to do gorm v1-like Save, which is an upsert function.

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

No branches or pull requests

3 participants