You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have two structs I'm currently trying to link via foreign key:
type Child struct{
ID int `pg:",pk"`
MyFK int
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt time.Time `pg:",soft_delete"`
Base Base `pg:"fk:my_fk"`
}
type Base struct{
ID int `pg:",pk"`
FieldToReference int `pg:",unique"`
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt time.Time `pg:",soft_delete"`
}
I want the "MyFK" field of my child struct to reference the "FieldToReference" field of the base struct. How do I accomplish this? MyFK by default references the ID field instead of my target field.
Expected Behavior
The table to establish a foreign key bewteen MyFK and FieldToReference
Current Behavior
The table instead connects MyFK to ID,
Steps to Reproduce
type Child struct{
ID int `pg:",pk"`
MyFK int
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt time.Time `pg:",soft_delete"`
Base Base `pg:"fk:my_fk"`
}
type Base struct{
ID int `pg:",pk"`
FieldToReference int `pg:",unique"`
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt time.Time `pg:",soft_delete"`
}
func main(){
db.Model( &Base{}, &Child{}).CreateTable(&orm.CreateTableOptions{
FKConstraints: true,
})
}
The text was updated successfully, but these errors were encountered:
I have two structs I'm currently trying to link via foreign key:
I want the "MyFK" field of my child struct to reference the "FieldToReference" field of the base struct. How do I accomplish this?
MyFK
by default references theID
field instead of my target field.Expected Behavior
The table to establish a foreign key bewteen
MyFK
andFieldToReference
Current Behavior
The table instead connects
MyFK
toID
,Steps to Reproduce
The text was updated successfully, but these errors were encountered: