Skip to content

Commit

Permalink
fix panic
Browse files Browse the repository at this point in the history
  • Loading branch information
sjqzhang committed Feb 10, 2023
1 parent c496747 commit 0bf9ad6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions mockdb/mock_gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func (m *MockGORM) doRecord(scope *gorm.Scope) {
break
}
}
if id == "" {
if strings.ToLower(id) != "id" {
return
}
for i := 0; i < rValue.Len(); i++ {
Expand All @@ -410,11 +410,13 @@ func (m *MockGORM) doRecord(scope *gorm.Scope) {
if item.IsValid() && item.FieldByName(id).Kind() == reflect.Ptr {

if item.FieldByName(id).Elem().Interface() != nil {

m.recorder[tableName].Add(item.FieldByName(id).Elem().Interface())
}
} else {

if item.FieldByName(id).Interface() != nil {

m.recorder[tableName].Add(item.FieldByName(id).Interface())
}

Expand All @@ -430,19 +432,21 @@ func (m *MockGORM) doRecord(scope *gorm.Scope) {
break
}
}
if id == "" {
if strings.ToLower(id) != "id" {
return
}
if !rValue.FieldByName(id).IsValid() {
return
}
if rValue.FieldByName(id).Kind() == reflect.Ptr {

if rValue.FieldByName(id).Elem().Interface()!=nil {
if rValue.FieldByName(id).Elem().Interface() != nil {

m.recorder[tableName].Add(rValue.FieldByName(id).Elem().Interface())
}
} else {
if rValue.FieldByName(id).Interface() != nil {

m.recorder[tableName].Add(rValue.FieldByName(id).Interface())
}
}
Expand Down

0 comments on commit 0bf9ad6

Please sign in to comment.