protoc-gen-gorm
protoc-gen-gorm copied to clipboard
Support for a Foreign Key referencing a Composite Primary Key
Is it possible for a Foreign Key to reference a composite key?
I try something like this:
message Foo {
option (gorm.opts).ormable = true;
string id = 1;
int64 version = 2;
repeated Bar bars = 3 [(gorm.field).has_many = {foreignkey: "FooId,FooVersion"}];
}
message Bar {
option (gorm.opts).ormable = true;
string id = 1;
int64 version = 2;
}
and the generated code produces this:
type FooORM struct {
Bars []*BarORM `gorm:"foreignkey:FooId,FooVersion;association_foreignkey:Id"`
Id string
Version int64
}
type BarORM struct {
FooId, FooVersion *string
Id string
Version int64
}
Is it possible to specify what the foreign keys reference, via https://gorm.io/docs/has_many.html#Override-References
Essentially, I want to generate code that looks like this:
type FooORM struct {
Bars []*BarORM `gorm:"foreignkey:FooId,FooVersion;References:Id,Version"`
Id string
Version int64
}
type BarORM struct {
FooId *string
FooVersion *int64
Id string
Version int64
}
I have the same problem, have you figured it out yet?
I'm also facing the same challenge, @frobones @mohakamg Hove you guys found any solution to this ?