blob: 1ccf37f5aad0695de763dca66d318816cb02216b (
plain)
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
|
package models
type User struct {
ID uint `gorm:"primaryKey" json:"id"`
Username string `gorm:"unique;not null" json:"username"`
Password string `gorm:"not null" json:"-"`
Blogs []Blog `gorm:"foreignKey:UserID" json:"blogs"`
Comments []Comment `gorm:"foreignKey:UserID" json:"comments"`
}
type Blog struct {
ID uint `gorm:"primaryKey" json:"id"`
Title string `gorm:"not null" json:"title"`
Content string `gorm:"not null" json:"content"`
UserID uint `gorm:"not null" json:"user_id"`
User User `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"user"`
Comments []Comment `gorm:"foreignKey:BlogID" json:"comments"`
}
type Comment struct {
ID uint `gorm:"primaryKey" json:"id"`
Content string `gorm:"not null" json:"content"`
UserID uint `gorm:"not null" json:"user_id"`
BlogID uint `gorm:"not null" json:"blog_id"`
User User `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"user"`
Blog Blog `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"blog"`
}
|