Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preloading with foreignKey and references overwrite #671

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cstaud
Copy link

@cstaud cstaud commented Dec 15, 2023

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"`
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant