I want to maintain a 1 to 1 relationship but whenever I try to save a record, the user table will get updated but there will be a new record created in the profile table rather than updating the associated profile record.
db.Model(&user).Save(&user)
Please let me know what i'm doing wrong here.
I have already referred to GORM Crud Documentation including the answer here https://stackoverflow.com/a/39333848/12066040
but seems like I'm missing something.
type User struct {
UserID uint `gorm:"primary_key"`
Name string
// Profile
FkProfileID uint `gorm:"null;index; DEFAULT:null"`
Profile Profile `gorm:"foreignkey:FkProfileID"`
}
type Profile struct {
ProfileID uint `gorm:"primary_key"`
ProfileSummary string
}
Expected Result:
Update both User and Profile tables when the profile record already exists for a user.