type A struct{
Id int64 `gorm:"primaryKey"`
Bs []B `gorm:"foreignKey:MyID"`
}
type B struct{
MyID string `gorm:"primaryKey"`
}
...
var models = []interface{}{A{},B{}}
db.AutoMigrate(models...)
Create on postgres db level:
A: id:bigint
B: my_id: bigint (!)
Expected answer
The primary key of B should be a String as defined in the gorm syntax.... Or am I doing something wrong?
Your Question
Is it possible to use a String as a specific ForeignKey ? Using PostgreSQL Adapter
The document you expected this should be explained
https://gorm.io/docs/has_many.html offers the possibility to change the default foreignKey.
Example:
Create on postgres db level:
Expected answer
The primary key of B should be a String as defined in the gorm syntax.... Or am I doing something wrong?
P.S. Is this related to https://github.com/go-gorm/postgres/pull/111