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

Check gorm.Model usage #55

Open
thisisommore opened this issue Oct 15, 2022 · 0 comments
Open

Check gorm.Model usage #55

thisisommore opened this issue Oct 15, 2022 · 0 comments

Comments

@thisisommore
Copy link
Contributor

thisisommore commented Oct 15, 2022

It is used for referring the model explicitly, but it is also used to update fields of existing record without the need to provide where condition separately rather in itself with struct passed to db.Model, also it is used for activating the association mode.
It can get trickier and can attract mistakes with it usage and can lead to bugs and also critical issues.

So we need to verify the usage throughout the app and make sure it is only used as per docs and not where it can be used.
For example possible mistake,

db.Model(&User{Name:"Tom"}).First(&user)

Here it is used as where condition which will not work and will return any first record present in table without matching the name Tom

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

No branches or pull requests

1 participant