-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Closed
Labels
type:with reproduction stepswith reproduction stepswith reproduction steps
Description
Playground
Edit: Here is the root cause:
go-gorm/playground#361
Description
Im Getting the panic("reflect: Field index out of range") for
err := db.Set(SettingAutoUpdate, false).Create(entity).Error
Where entity is:
type Model struct {
Id int64 `gorm:"type:bigserial;primary_key" json:"id"`
CreatedAt time.Time `sql:"DEFAULT:NOW()" json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
type Organisation struct {
Model
Name string `json:"name"`
Description string
LogoFileId *int64 `gorm:"default: null" json:"logoFileId"`
LogoName string
}
Here is where the panic occurs. tt.fields is ´5.
// create valuer, setter when parse struct
func (field *Field) setupValuerAndSetter() {
// ValueOf
switch {
case len(field.StructField.Index) == 1:
field.ValueOf = func(value reflect.Value) (interface{}, bool) {
fieldValue := reflect.Indirect(value).Field(field.StructField.Index[0])
/* [...] */
// Field returns the i'th field of the struct v.
// It panics if v's Kind is not Struct or i is out of range.
func (v Value) Field(i int) Value {
if v.kind() != Struct {
panic(&ValueError{"reflect.Value.Field", v.kind()})
}
tt := (*structType)(unsafe.Pointer(v.typ))
if uint(i) >= uint(len(tt.fields)) {
panic("reflect: Field index out of range")
}
/* [...] */
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
type:with reproduction stepswith reproduction stepswith reproduction steps