Your Question
So I have a model,below:
type Conversation struct {
ConversationId string `gorm:"primaryKey"`
StartTime *time.Time
EndTime *time.Time
Title string
Status string // Created、Activate、Idle、Expired、Abandoned、Renewed、Terminated、Invalidated、Migrated
CreatedBy string
LastActive *time.Time
MessageCount int
Language string
TokensConsumed int64
}
I create 2 records and it success. But i try query this 2 like a user created 2 conversation in my context got an err:
func (rd *ResourceDao) GetConversationsByUserId(userId string) ([]model.Conversation, error) {
var cs []model.Conversation
err := rd.DB.Model(&model.Conversation{}).
Where("created_by = ?", userId).
Find(&cs).Error
return cs, err
}
err info
[29.284ms] [rows:2] SELECT * FROM `conversation` WHERE created_by = 'user-4fbfe0c2-f035-11ee-98b4-9ae0cc7dbf08'
2024-04-17 14:52:13 file=runtime/panic.go:770 level=error panic recovered: runtime error: index out of range [0] with length 0
2024-04-17 14:52:13 file=runtime/panic.go:770 level=error goroutine 74 [running]:
i reproduce it in playground:https://github.com/go-gorm/playground/pull/719