I tried to make models Association ForeignKey on PostgreSQL for the Person it belongs to Data and Data belongs to Person this is my struct
type (
Data struct {
ID uint `gorm:"auto_increment"`
PersonID uint
Person *Person `gorm:"foreignkey:id;association_foreignkey:PersonID"`
Birthday *time.Time
Salary float64 `gorm:"type:money"`
}
Person struct {
gorm.Model
Email string `gorm:"type:varchar(100);unique_index;not null"`
Password string `gorm:"type:varchar(100);not null"`
Role string `gorm:"type:varchar(30);not null"`
DataID uint
Data *Data `gorm:"foreignkey:id;association_foreignkey:DataID"`
}
)
I want to on Data table has Person_id
is to be foreign key from Person table, and as well the Person table has Data_id
to be foreign key from the data table after I see on ER Diagram on my DBeaver, those are not created as I wish :( it is not any relationship on ER Diagram, I am sure my Association on above wrong, can anyone give me some info to fix that?