mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-05-13 15:25:20 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bce27f7ed2 |
@@ -76,9 +76,14 @@ func GetJSONNameForField(modelType reflect.Type, fieldName string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle pointer types
|
// Unwrap pointer and slice indirections to reach the struct type
|
||||||
if modelType.Kind() == reflect.Ptr {
|
for {
|
||||||
modelType = modelType.Elem()
|
switch modelType.Kind() {
|
||||||
|
case reflect.Ptr, reflect.Slice:
|
||||||
|
modelType = modelType.Elem()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if modelType.Kind() != reflect.Struct {
|
if modelType.Kind() != reflect.Struct {
|
||||||
|
|||||||
@@ -541,9 +541,14 @@ func collectSQLColumnsFromType(typ reflect.Type, columns *[]string, scanOnlyEmbe
|
|||||||
func IsColumnWritable(model any, columnName string) bool {
|
func IsColumnWritable(model any, columnName string) bool {
|
||||||
modelType := reflect.TypeOf(model)
|
modelType := reflect.TypeOf(model)
|
||||||
|
|
||||||
// Unwrap pointers to get to the base struct type
|
// Unwrap pointers and slices to get to the base struct type
|
||||||
for modelType != nil && modelType.Kind() == reflect.Pointer {
|
for modelType != nil {
|
||||||
modelType = modelType.Elem()
|
switch modelType.Kind() {
|
||||||
|
case reflect.Ptr, reflect.Slice:
|
||||||
|
modelType = modelType.Elem()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate that we have a struct type
|
// Validate that we have a struct type
|
||||||
@@ -878,8 +883,14 @@ func GetRelationType(model interface{}, fieldName string) RelationType {
|
|||||||
return RelationUnknown
|
return RelationUnknown
|
||||||
}
|
}
|
||||||
|
|
||||||
if modelType.Kind() == reflect.Ptr {
|
// Unwrap pointer → slice → pointer chains to reach the underlying struct
|
||||||
modelType = modelType.Elem()
|
for {
|
||||||
|
switch modelType.Kind() {
|
||||||
|
case reflect.Ptr, reflect.Slice:
|
||||||
|
modelType = modelType.Elem()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if modelType == nil || modelType.Kind() != reflect.Struct {
|
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 {
|
func GetValidJSONFieldNames(modelType reflect.Type) map[string]bool {
|
||||||
validFields := make(map[string]bool)
|
validFields := make(map[string]bool)
|
||||||
|
|
||||||
// Unwrap pointers to get to the base struct type
|
// Unwrap pointers and slices to get to the base struct type
|
||||||
for modelType != nil && modelType.Kind() == reflect.Pointer {
|
for modelType != nil {
|
||||||
modelType = modelType.Elem()
|
switch modelType.Kind() {
|
||||||
|
case reflect.Ptr, reflect.Slice:
|
||||||
|
modelType = modelType.Elem()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if modelType == nil || modelType.Kind() != reflect.Struct {
|
if modelType == nil || modelType.Kind() != reflect.Struct {
|
||||||
@@ -1535,8 +1551,13 @@ func getRelationModelSingleLevel(model interface{}, fieldName string) interface{
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if modelType.Kind() == reflect.Ptr {
|
for {
|
||||||
modelType = modelType.Elem()
|
switch modelType.Kind() {
|
||||||
|
case reflect.Ptr, reflect.Slice:
|
||||||
|
modelType = modelType.Elem()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if modelType == nil || modelType.Kind() != reflect.Struct {
|
if modelType == nil || modelType.Kind() != reflect.Struct {
|
||||||
@@ -1599,17 +1620,16 @@ func getRelationModelSingleLevel(model interface{}, fieldName string) interface{
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if targetType.Kind() == reflect.Slice {
|
for {
|
||||||
targetType = targetType.Elem()
|
switch targetType.Kind() {
|
||||||
if targetType == nil {
|
case reflect.Ptr, reflect.Slice:
|
||||||
return nil
|
targetType = targetType.Elem()
|
||||||
}
|
if targetType == nil {
|
||||||
}
|
return nil
|
||||||
if targetType.Kind() == reflect.Ptr {
|
}
|
||||||
targetType = targetType.Elem()
|
continue
|
||||||
if targetType == nil {
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if targetType.Kind() != reflect.Struct {
|
if targetType.Kind() != reflect.Struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user