model define

main
han-joker 2 years ago
parent cc82193e20
commit c9f638396b

@ -42,7 +42,7 @@ type TypeMap struct {
} }
func Migrate() { func Migrate() {
if err := DB.Debug().AutoMigrate(&Service{}, &IAndC{}, &FieldTag{}, &TypeMap{}, &Post{}, &Category{}, &PostCategory{}, &Box{}); err != nil { if err := DB.Debug().AutoMigrate(&Blog{}, &Service{}, &IAndC{}, &FieldTag{}, &TypeMap{}, &Post{}, &Category{}, &PostCategory{}, &Box{}); err != nil {
log.Fatal(err) log.Fatal(err)
} }
} }
@ -279,3 +279,32 @@ func CustomSerializer() {
DB.First(newPaper, paper.ID) DB.First(newPaper, paper.ID)
fmt.Printf("%+v\n", newPaper) fmt.Printf("%+v\n", newPaper)
} }
// 用于处理Blog新增的请求模型
type BlogPost struct {
BlogBasic
}
// 用于更新
type BlogPut struct {
ID uint
BlogBasic
}
// 用于DB表交互的模型
type Blog struct {
gorm.Model
BlogBasic
Author `gorm:"embeddedPrefix:author_"`
}
type BlogBasic struct {
Subject string
Summary string
Content string
}
type Author struct {
Name string
Emaile string
}

Loading…
Cancel
Save