gorm.io icon indicating copy to clipboard operation
gorm.io copied to clipboard

[Question] Wondering how to link up two structs to one in AutoMigrate

Open chrisbward opened this issue 1 year ago • 1 comments

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 avatar Oct 16 '22 01:10 chrisbward

https://github.com/go-gorm/gorm.io/issues/343

Seems like this has been asked before!

chrisbward avatar Oct 16 '22 12:10 chrisbward