mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-05-13 15:25:20 +00:00
fix: 🐛 Fixed array to slice array resolution on reflection GetRelationType
Some checks failed
Build , Vet Test, and Lint / Run Vet Tests (1.23.x) (push) Failing after -35m20s
Build , Vet Test, and Lint / Run Vet Tests (1.24.x) (push) Failing after -35m20s
Build , Vet Test, and Lint / Lint Code (push) Failing after -35m20s
Build , Vet Test, and Lint / Build (push) Failing after -35m20s
Tests / Unit Tests (push) Failing after -35m21s
Tests / Integration Tests (push) Failing after -35m21s
Some checks failed
Build , Vet Test, and Lint / Run Vet Tests (1.23.x) (push) Failing after -35m20s
Build , Vet Test, and Lint / Run Vet Tests (1.24.x) (push) Failing after -35m20s
Build , Vet Test, and Lint / Lint Code (push) Failing after -35m20s
Build , Vet Test, and Lint / Build (push) Failing after -35m20s
Tests / Unit Tests (push) Failing after -35m21s
Tests / Integration Tests (push) Failing after -35m21s
This commit is contained in:
@@ -76,9 +76,14 @@ func GetJSONNameForField(modelType reflect.Type, fieldName string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Handle pointer types
|
||||
if modelType.Kind() == reflect.Ptr {
|
||||
// Unwrap pointer and slice indirections to reach the struct type
|
||||
for {
|
||||
switch modelType.Kind() {
|
||||
case reflect.Ptr, reflect.Slice:
|
||||
modelType = modelType.Elem()
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
if modelType.Kind() != reflect.Struct {
|
||||
|
||||
@@ -541,9 +541,14 @@ func collectSQLColumnsFromType(typ reflect.Type, columns *[]string, scanOnlyEmbe
|
||||
func IsColumnWritable(model any, columnName string) bool {
|
||||
modelType := reflect.TypeOf(model)
|
||||
|
||||
// Unwrap pointers to get to the base struct type
|
||||
for modelType != nil && modelType.Kind() == reflect.Pointer {
|
||||
// Unwrap pointers and slices to get to the base struct type
|
||||
for modelType != nil {
|
||||
switch modelType.Kind() {
|
||||
case reflect.Ptr, reflect.Slice:
|
||||
modelType = modelType.Elem()
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
// Validate that we have a struct type
|
||||
@@ -878,8 +883,14 @@ func GetRelationType(model interface{}, fieldName string) RelationType {
|
||||
return RelationUnknown
|
||||
}
|
||||
|
||||
if modelType.Kind() == reflect.Ptr {
|
||||
// Unwrap pointer → slice → pointer chains to reach the underlying struct
|
||||
for {
|
||||
switch modelType.Kind() {
|
||||
case reflect.Ptr, reflect.Slice:
|
||||
modelType = modelType.Elem()
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
if modelType == nil || modelType.Kind() != reflect.Struct {
|
||||
@@ -1472,9 +1483,14 @@ func convertToFloat64(value interface{}) (float64, bool) {
|
||||
func GetValidJSONFieldNames(modelType reflect.Type) map[string]bool {
|
||||
validFields := make(map[string]bool)
|
||||
|
||||
// Unwrap pointers to get to the base struct type
|
||||
for modelType != nil && modelType.Kind() == reflect.Pointer {
|
||||
// Unwrap pointers and slices to get to the base struct type
|
||||
for modelType != nil {
|
||||
switch modelType.Kind() {
|
||||
case reflect.Ptr, reflect.Slice:
|
||||
modelType = modelType.Elem()
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
if modelType == nil || modelType.Kind() != reflect.Struct {
|
||||
@@ -1535,8 +1551,13 @@ func getRelationModelSingleLevel(model interface{}, fieldName string) interface{
|
||||
return nil
|
||||
}
|
||||
|
||||
if modelType.Kind() == reflect.Ptr {
|
||||
for {
|
||||
switch modelType.Kind() {
|
||||
case reflect.Ptr, reflect.Slice:
|
||||
modelType = modelType.Elem()
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
if modelType == nil || modelType.Kind() != reflect.Struct {
|
||||
@@ -1599,17 +1620,16 @@ func getRelationModelSingleLevel(model interface{}, fieldName string) interface{
|
||||
return nil
|
||||
}
|
||||
|
||||
if targetType.Kind() == reflect.Slice {
|
||||
for {
|
||||
switch targetType.Kind() {
|
||||
case reflect.Ptr, reflect.Slice:
|
||||
targetType = targetType.Elem()
|
||||
if targetType == nil {
|
||||
return nil
|
||||
}
|
||||
continue
|
||||
}
|
||||
if targetType.Kind() == reflect.Ptr {
|
||||
targetType = targetType.Elem()
|
||||
if targetType == nil {
|
||||
return nil
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
if targetType.Kind() != reflect.Struct {
|
||||
|
||||
Reference in New Issue
Block a user