-
Notifications
You must be signed in to change notification settings - Fork 0
/
vote_model.go
31 lines (27 loc) · 874 Bytes
/
vote_model.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package models
import (
"gorm.io/gorm"
"time"
)
type Vote struct {
ID uint64 `gorm:"primaryKey;autoIncrement" json:"id"`
Choice Choice `gorm:"foreignKey:ChoiceID" json:"choice"`
ChoiceID uint64 `json:"choice_id"`
User User `gorm:"foreignKey:UserID" json:"user"`
UserID uint64 `json:"user_id"`
Poll Poll `gorm:"foreignKey:PollID" json:"poll"`
PollID uint64 `json:"poll_id"`
Division Division `gorm:"foreignKey:DivisionID" json:"division"`
DivisionID uint64 `json:"division_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (vote *Vote) BeforeCreate(tx *gorm.DB) (err error) {
vote.CreatedAt = time.Now()
vote.UpdatedAt = time.Now()
return nil
}
func (vote *Vote) BeforeUpdate(tx *gorm.DB) (err error) {
vote.UpdatedAt = time.Now()
return nil
}