I have this model:
type Process struct {
Asset Asset `json:"asset" binding:"required"`
Buyer Person `json:"buyer" binding:"required"`
Payer Person `json:"payer" binding:"required"`
}
asset and person is a foreign key, this is how i set it to be foregin key (if there is a better way you can also tell me):
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"
}
------------ main func -----------
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")
for other tables of course, I want to search process by the Asset id, how can I do that? I don't know if you need more information, but if you do, please tell me what information I can add so the question will be more understandable