diff options
| author | roerick <roerick@wyo.town> | 2025-10-17 15:32:19 -0600 |
|---|---|---|
| committer | roerick <roerick@wyo.town> | 2025-10-17 15:32:19 -0600 |
| commit | ce61d3db96e0539c8df1886ac635e7e85dbde31f (patch) | |
| tree | 8af7c0eda03b91273ebffbde5799e4436b04cac6 /models | |
initial commit, models not working
Diffstat (limited to 'models')
| -rw-r--r-- | models/models.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/models/models.go b/models/models.go new file mode 100644 index 0000000..1ccf37f --- /dev/null +++ b/models/models.go @@ -0,0 +1,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"` +} + + |
