-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
ShouldBind sets a default value to *time.Time, cant use with gorm package #1364
Comments
Using |
@syssam yes it works, but bad that now i cant embed predefined struct gorm.Model and must rewrite every struct:
|
Surely, However you can custom your own gorm.Model |
binding:"-" is for validation |
the binding tag is base on https://github.com/gin-gonic/gin/blob/master/binding/default_validator.go |
@bsbak Hi, could you tell me how to solve this problem? I tried, write a BaseModel just like gorm.Model, and set the Hope you have solved the problem, thanks in advance. |
@yangjianhua without seeing ur code cant say anything. form:"-" solved my problem. Try use db.Omit("created_at, updated_at, deleted_at").Create(...) |
@bsbak Thanks you, but omit only work on update method, right? It seems not work on create |
I have struct field
DeletedAt *time.Time `sql:"index"`
After ctx.ShouldBind(&mystruct) the value of DeletedAt field is not
nil
, but must be, becouse gorm(sql) package cant auto generate NULL for that field.The problem is there:
github.com\gin-gonic\gin\binding\form_mapping.go
The text was updated successfully, but these errors were encountered: