[Question] Wondering how to link up two structs to one in AutoMigrate
chrisbward opened this issue · 1 comments
chrisbward commented
Hi!
Say I have the following Structs;
type Address struct {
gorm.Model
AddressLine1 string `json:"addressLine1"`
AddressLine2 string `json:"addressLine2"`
City string `json:"city"`
PostZipCode string `json:"postZipCode"`
Country string `json:"country"`
}
type BillingAddress struct {
gorm.Model
OrderID uint
Person Person `json:"person"`
Address Address `gorm:"references:Address" json:"address"`
}
type ShippingAddress struct {
gorm.Model
OrderID uint
Address Address `gorm:"references:Address" json:"address"`
}
I am receiving messages that Address must have BOTH BillingAddressID
and ShippngAddressID
fields, when I would not expect to do this traditionally... have I missed something?
Chris
chrisbward commented
Seems like this has been asked before!