init
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// #[derive(Debug, Clone, FromRow, Serialize, Deserialize)]
|
||||
@@ -26,3 +27,10 @@ type Message struct {
|
||||
EditedAt *time.Time `gorm:"default:null" json:"edited_at,omitempty"`
|
||||
ReplyToID *uuid.UUID `gorm:"index" json:"reply_to_id,omitempty"`
|
||||
}
|
||||
|
||||
func (s *Message) BeforeCreate(tx *gorm.DB) (err error) {
|
||||
if s.ID == uuid.Nil {
|
||||
s.ID = uuid.New()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user