Skip to content

fix:throw model value required error #6031

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

Merged
merged 5 commits into from
Feb 8, 2023

Conversation

a631807682
Copy link
Member

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

What did this pull request do?

close #6030

User Case Description

statement.go Outdated
@@ -120,6 +120,8 @@ func (stmt *Statement) QuoteTo(writer clause.Writer, field interface{}) {
write(v.Raw, stmt.Schema.PrioritizedPrimaryField.DBName)
} else if len(stmt.Schema.DBNames) > 0 {
write(v.Raw, stmt.Schema.DBNames[0])
} else {
stmt.DB.AddError(ErrModelValueRequired) //nolint:typecheck,errcheck

Choose a reason for hiding this comment

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

Why we don't use ErrPrimaryKeyRequired.

I am not very familiar with gorm. Maybe I asked a stupid question.

I am not very sure what the meaning ErrPrimaryKeyRequired and ErrModelValueRequired are.

Copy link
Member Author

Choose a reason for hiding this comment

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

@ExerciseBook This has nothing to do with the primary key, it's because there aren't any accessible fields in the model.
The use of ErrModelValueRequired here is indeed misleading. It prompts the user to use the model, but the problem here is that the user uses the wrong model.

@jinzhu jinzhu merged commit 878ac51 into go-gorm:master Feb 8, 2023
@a631807682 a631807682 deleted the fix_pk_require branch February 8, 2023 05:46
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.

Feature Request: Model validation
3 participants