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

Reference Key not passed to child model on creation #4081

Closed
ghost opened this issue Feb 12, 2021 · 1 comment
Closed

Reference Key not passed to child model on creation #4081

ghost opened this issue Feb 12, 2021 · 1 comment
Assignees
Labels
type:with reproduction steps with reproduction steps

Comments

@ghost
Copy link

ghost commented Feb 12, 2021

GORM Playground Link

go-gorm/playground#277

Description

The reference key denoted in the parent model should be passed on to the child (has one) model on creation.. However this does not happen via gorm v2

@ghost ghost assigned jinzhu Feb 12, 2021
@github-actions github-actions bot added the type:with reproduction steps with reproduction steps label Feb 12, 2021
@jinzhu jinzhu closed this as completed in 628a0ae Feb 15, 2021
@jinzhu
Copy link
Member

jinzhu commented Feb 15, 2021

Fixed, thank you for your report, btw, you need to create a unique index for the uuid field to use it as a foreign key. e.g:

type User struct {
	gorm.Model
	Name      string
	Age       uint
	Birthday  *time.Time
	Account   Account
	Pets      []*Pet
	Toys      []Toy `gorm:"polymorphic:Owner"`
	CompanyID *int
	Company   Company
	UUID      string   `gorm:"size:20;uniqueIndex"`
	Aux       *UserAux `gorm:"foreignkey:UUID;references:uuid"`
	ManagerID *uint
	Manager   *User
	Team      []User     `gorm:"foreignkey:ManagerID"`
	Languages []Language `gorm:"many2many:UserSpeak"`
	Friends   []*User    `gorm:"many2many:user_friends"`
	Active    bool
}

cgxxv pushed a commit to cgxxv/gorm that referenced this issue Mar 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:with reproduction steps with reproduction steps
Projects
None yet
Development

No branches or pull requests

1 participant