所以我对Gorm
还很陌生,还在玩它,但我似乎不能用删除级联来工作.以下是我的模特:
type Base struct {
Id string `json:"id" gorm:"type:uuid;primary_key"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type User struct {
Base
Role string `json:"role"`
Username string `json:"username" gorm:"unique"`
Password string `json:"password"`
Profile Profile `gorm:"constraint:OnDelete:CASCADE;"`
}
type Profile struct {
Base
UserId string `json:"user_id"`
Name string `json:"name"`
Bio string `json:"bio" gorm:"default:hello world!"`
Age uint8 `json:"age"`
}
一百零七
以下是我如何运行删除操作:
...
id := "my-uuid" // this would be a real value. this is just an example
Database.Where("id = ?", id).Delete(&models.User{})
...
我做错了什么?
谢谢!
Edit: 我意识到了这question点,并试着遵循它,但我似乎无法让它奏效.