gorm.io
gorm.io copied to clipboard
[Question] Wondering how to link up two structs to one in AutoMigrate
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
https://github.com/go-gorm/gorm.io/issues/343
Seems like this has been asked before!