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

fix deprecated reflect.PtrTo reflect.PointerTo usage #7366

Merged
merged 4 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions callbacks/associations.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func SaveBeforeAssociations(create bool) func(db *gorm.DB) {
)

if !isPtr {
fieldType = reflect.PtrTo(fieldType)
fieldType = reflect.PointerTo(fieldType)
}

elems := reflect.MakeSlice(reflect.SliceOf(fieldType), 0, 10)
Expand Down Expand Up @@ -126,7 +126,7 @@ func SaveAfterAssociations(create bool) func(db *gorm.DB) {
)

if !isPtr {
fieldType = reflect.PtrTo(fieldType)
fieldType = reflect.PointerTo(fieldType)
}

elems := reflect.MakeSlice(reflect.SliceOf(fieldType), 0, 10)
Expand Down Expand Up @@ -195,7 +195,7 @@ func SaveAfterAssociations(create bool) func(db *gorm.DB) {
fieldType := rel.Field.IndirectFieldType.Elem()
isPtr := fieldType.Kind() == reflect.Ptr
if !isPtr {
fieldType = reflect.PtrTo(fieldType)
fieldType = reflect.PointerTo(fieldType)
}
elems := reflect.MakeSlice(reflect.SliceOf(fieldType), 0, 10)
identityMap := map[string]bool{}
Expand Down Expand Up @@ -268,11 +268,11 @@ func SaveAfterAssociations(create bool) func(db *gorm.DB) {
fieldType := rel.Field.IndirectFieldType.Elem()
isPtr := fieldType.Kind() == reflect.Ptr
if !isPtr {
fieldType = reflect.PtrTo(fieldType)
fieldType = reflect.PointerTo(fieldType)
}
elems := reflect.MakeSlice(reflect.SliceOf(fieldType), 0, 10)
distinctElems := reflect.MakeSlice(reflect.SliceOf(fieldType), 0, 10)
joins := reflect.MakeSlice(reflect.SliceOf(reflect.PtrTo(rel.JoinTable.ModelType)), 0, 10)
joins := reflect.MakeSlice(reflect.SliceOf(reflect.PointerTo(rel.JoinTable.ModelType)), 0, 10)
objs := []reflect.Value{}

appendToJoins := func(obj reflect.Value, elem reflect.Value) {
Expand Down
4 changes: 2 additions & 2 deletions scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ func prepareValues(values []interface{}, db *DB, columnTypes []*sql.ColumnType,
if db.Statement.Schema != nil {
for idx, name := range columns {
if field := db.Statement.Schema.LookUpField(name); field != nil {
values[idx] = reflect.New(reflect.PtrTo(field.FieldType)).Interface()
values[idx] = reflect.New(reflect.PointerTo(field.FieldType)).Interface()
continue
}
values[idx] = new(interface{})
}
} else if len(columnTypes) > 0 {
for idx, columnType := range columnTypes {
if columnType.ScanType() != nil {
values[idx] = reflect.New(reflect.PtrTo(columnType.ScanType())).Interface()
values[idx] = reflect.New(reflect.PointerTo(columnType.ScanType())).Interface()
} else {
values[idx] = new(interface{})
}
Expand Down
2 changes: 1 addition & 1 deletion schema/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,6 @@ func (field *Field) setupNewValuePool() {
}

if field.NewValuePool == nil {
field.NewValuePool = poolInitializer(reflect.PtrTo(field.IndirectFieldType))
field.NewValuePool = poolInitializer(reflect.PointerTo(field.IndirectFieldType))
}
}
2 changes: 1 addition & 1 deletion schema/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func appendSettingFromTag(tag reflect.StructTag, value string) reflect.StructTag
// GetRelationsValues get relations's values from a reflect value
func GetRelationsValues(ctx context.Context, reflectValue reflect.Value, rels []*Relationship) (reflectResults reflect.Value) {
for _, rel := range rels {
reflectResults = reflect.MakeSlice(reflect.SliceOf(reflect.PtrTo(rel.FieldSchema.ModelType)), 0, 1)
reflectResults = reflect.MakeSlice(reflect.SliceOf(reflect.PointerTo(rel.FieldSchema.ModelType)), 0, 1)

appendToResults := func(value reflect.Value) {
if _, isZero := rel.Field.ValueOf(ctx, value); !isZero {
Expand Down
Loading