Skip to content

fix:throw model value required error#6031

Merged
jinzhu merged 5 commits intogo-gorm:masterfrom
a631807682:fix_pk_require
Feb 8, 2023
Merged

fix:throw model value required error#6031
jinzhu merged 5 commits intogo-gorm:masterfrom
a631807682:fix_pk_require

Conversation

@a631807682
Copy link
Copy Markdown
Member

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

What did this pull request do?

close #6030

User Case Description

Comment thread statement.go Outdated
} else if len(stmt.Schema.DBNames) > 0 {
write(v.Raw, stmt.Schema.DBNames[0])
} else {
stmt.DB.AddError(ErrModelValueRequired) //nolint:typecheck,errcheck
Copy link
Copy Markdown

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
Copy Markdown
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