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"` }