我有这个模型:
type Process struct {
Asset Asset `json:"asset" binding:"required"`
Buyer Person `json:"buyer" binding:"required"`
Payer Person `json:"payer" binding:"required"`
}
资产和人是外键,这就是我将其设置为前瞻键的方式(如果有更好的方法,您也可以告诉我):
type DBProcess struct {
DBBase
Asset uint `gorm:"column:asset_id" json:"-"`
Buyer uint `gorm:"column:buyer_id" json:"-"`
Payer uint `gorm:"column:payer_id" json:"-"`
}
func (DBProcess) TableName() string {
return "t_processes"
}
------------主要功能-----------
db.Model(&models.DBProcess{}).AddForeignKey("asset_id", "t_assets(id)", "RESTRICT", "RESTRICT")
db.Model(&models.DBProcess{}).AddForeignKey("buyer_id", "t_persons(id)", "RESTRICT", "RESTRICT")
db.Model(&models.DBProcess{}).AddForeignKey("payer_id", "t_persons(id)", "RESTRICT", "RESTRICT")
对于其他表格,我想按资产ID搜索流程,该怎么做? 我不知道您是否需要更多信息,但是如果您需要,请告诉我可以添加哪些信息,这样问题将更容易理解