Skip to content

Commit 43c5ca3

Browse files
committed
add new model Macro raahii#1
1 parent 44b213a commit 43c5ca3

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

controllers/types.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,24 @@ type Paper struct {
1919
Abstract string `json:"abstract" gorm:"not null;type:text"`
2020
AbsUrl string `json:"url" gorm:"not null"`
2121
TarballUrl string `json:"tarball_url" gorm:"not null"`
22-
Macros string `json:"macros" gorm:"type:text"`
22+
Macros []Macro `json:"macros" gorm:"association_save_reference:true;foreignkey:PaperID"`
2323
Equations []Equation `json:"equations" gorm:"association_save_reference:true;foreignkey:PaperID"`
2424
}
2525

2626
func (Paper) TableName() string {
2727
return "papers"
2828
}
2929

30+
type Macro struct {
31+
Expression string `json:"expression" gorm:"not null;type:varchar(2000)"`
32+
Command string `json:"command" gorm:"not null;type:varchar(100)"`
33+
PaperID uint `json:"paper_id" gorm:"not null"`
34+
}
35+
36+
func (Macro) TableName() string {
37+
return "macros"
38+
}
39+
3040
type Author struct {
3141
Model
3242
Name string `json:"name" gorm:not null`

server.go

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func initApp(db *gorm.DB) {
2828
&controllers.Paper{},
2929
&controllers.Equation{},
3030
&controllers.Author{},
31+
&controllers.Macro{},
3132
}
3233
for _, model := range models {
3334
db.AutoMigrate(model)

0 commit comments

Comments
 (0)