go-gorm / playground

GORM Playground (Please Create PR for this project to report issues)
MIT License
89 stars 678 forks source link

preloading with foreignKey and references overwrite #671

Open cstaud opened 8 months ago

cstaud commented 8 months ago

Explain your user case and expected results

When using a belongs-to relation with foreignKey and references overwrite preloading does not work. (Adress2) When not overwriting it works as expected. (Address1)

type Country1 struct {
    Name string `gorm:"primaryKey"`
}

type Country2 struct {
    CName string `gorm:"primaryKey"`
}

type Address1 struct {
    CountryName string
    Country     Country1
}

type Address2 struct {
    CName   string
    Country Country2 `gorm:"foreignKey:CName;references:CName"`
}