cascade delete, and prevent report creation from creating nonexistent uploads
This commit is contained in:
+6
-2
@@ -32,7 +32,7 @@ type Report struct {
|
||||
ID string `gorm:"column:id;primaryKey"`
|
||||
UploadID string
|
||||
Reason string `gorm:"column:reason;not null"`
|
||||
Upload Upload `gorm:"foreignKey:UploadID"`
|
||||
Upload Upload `gorm:"foreignKey:UploadID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
|
||||
CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime"`
|
||||
}
|
||||
|
||||
@@ -63,7 +63,11 @@ func initDatabase(path string) (*gorm.DB, error) {
|
||||
}
|
||||
|
||||
func insertUpload(db *gorm.DB, upload *Upload) error {
|
||||
return db.Create(upload).Error
|
||||
return db.Omit("Upload").Create(upload).Error
|
||||
}
|
||||
|
||||
func insertReport(db *gorm.DB, report *Report) error {
|
||||
return db.Create(report).Error
|
||||
}
|
||||
|
||||
func getUploadById(db *gorm.DB, id string) (*Upload, error) {
|
||||
|
||||
Reference in New Issue
Block a user