Skip to content
This repository was archived by the owner on Jan 10, 2022. It is now read-only.

Commit 55f8e9e

Browse files
minor fix
1 parent 84ccacf commit 55f8e9e

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

core/gorm_persistence_storage.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"gorm.io/gorm/clause"
1010
"net/url"
1111
"reflect"
12+
"strconv"
1213
"strings"
1314
)
1415

@@ -724,11 +725,15 @@ func (afo *GormAdminFilterObjects) Search(field *Field, searchString string) {
724725
if searchField.Field.FieldType.Kind() == reflect.Struct {
725726
afo.Search(searchField.Field, searchString)
726727
continue
727-
} else if (fieldType1 == reflect.Uint) || (fieldType1 == reflect.Uint64) || (fieldType1 == reflect.Uint32) || (fieldType1 == reflect.Int64) || (fieldType1 == reflect.Int) || (fieldType1 == reflect.Int32) || (fieldType1 == reflect.Float32) || (fieldType1 == reflect.Float64) {
728+
} else if (fieldType1 == reflect.Uint) || (fieldType1 == reflect.Uint64) || (fieldType1 == reflect.Uint32) || (fieldType1 == reflect.Int64) || (fieldType1 == reflect.Int) || (fieldType1 == reflect.Int32) {
729+
searchID, err1 := strconv.Atoi(searchString)
730+
if err1 != nil {
731+
continue
732+
}
728733
operator := ExactGormOperator{}
729-
operator.Build(afo.GetUadminDatabase().Adapter, fullGormOperatorContext, searchField.Field, searchString, &SQLConditionBuilder{Type: "or"})
734+
operator.Build(afo.GetUadminDatabase().Adapter, fullGormOperatorContext, searchField.Field, searchID, &SQLConditionBuilder{Type: "or"})
730735
operator = ExactGormOperator{}
731-
operator.Build(afo.GetUadminDatabase().Adapter, paginatedGormOperatorContext, searchField.Field, searchString, &SQLConditionBuilder{Type: "or"})
736+
operator.Build(afo.GetUadminDatabase().Adapter, paginatedGormOperatorContext, searchField.Field, searchID, &SQLConditionBuilder{Type: "or"})
732737
} else {
733738
operator := IContainsGormOperator{}
734739
operator.Build(afo.GetUadminDatabase().Adapter, fullGormOperatorContext, searchField.Field, searchString, &SQLConditionBuilder{Type: "or"})
@@ -739,13 +744,17 @@ func (afo *GormAdminFilterObjects) Search(field *Field, searchString string) {
739744
afo.SetFullQuerySet(fullGormOperatorContext.Tx)
740745
afo.SetPaginatedQuerySet(fullGormOperatorContext.Tx)
741746
afo.SetLastError(afo.PaginatedGormQuerySet.GetLastError())
742-
} else if (fieldType == reflect.Uint) || (fieldType == reflect.Uint64) || (fieldType == reflect.Uint32) || (fieldType == reflect.Int64) || (fieldType == reflect.Int) || (fieldType == reflect.Int32) || (fieldType == reflect.Float32) || (fieldType == reflect.Float64){
747+
} else if (fieldType == reflect.Uint) || (fieldType == reflect.Uint64) || (fieldType == reflect.Uint32) || (fieldType == reflect.Int64) || (fieldType == reflect.Int) || (fieldType == reflect.Int32){
748+
searchID, err1 := strconv.Atoi(searchString)
749+
if err1 != nil {
750+
return
751+
}
743752
operator := ExactGormOperator{}
744753
gormOperatorContext := NewGormOperatorContext(afo.GetFullQuerySet(), afo.GetCurrentModel())
745-
operator.Build(afo.GetUadminDatabase().Adapter, gormOperatorContext, field, searchString, &SQLConditionBuilder{Type: "or"})
754+
operator.Build(afo.GetUadminDatabase().Adapter, gormOperatorContext, field, searchID, &SQLConditionBuilder{Type: "or"})
746755
afo.SetFullQuerySet(gormOperatorContext.Tx)
747756
gormOperatorContext = NewGormOperatorContext(afo.GetPaginatedQuerySet(), afo.GetCurrentModel())
748-
operator.Build(afo.GetUadminDatabase().Adapter, gormOperatorContext, field, searchString, &SQLConditionBuilder{Type: "or"})
757+
operator.Build(afo.GetUadminDatabase().Adapter, gormOperatorContext, field, searchID, &SQLConditionBuilder{Type: "or"})
749758
afo.SetPaginatedQuerySet(gormOperatorContext.Tx)
750759
afo.SetLastError(afo.PaginatedGormQuerySet.GetLastError())
751760
} else {

0 commit comments

Comments
 (0)