protoc-gen-gorm icon indicating copy to clipboard operation
protoc-gen-gorm copied to clipboard

fixing these tags were not generated on the ORM struct:

Open alkaaf opened this issue 4 years ago • 3 comments

these tags were not generated (recognized as empty and it hurts my head). i have strong thought that was a bug. i fixed it and tested it.

foreignkey association_foreignkey many2many jointable_foreignkey association_jointable_foreignkey association_autoupdate association_autocreate association_save_reference preload

alkaaf avatar Apr 08 '20 09:04 alkaaf

Hmm. When I test it by adding one of these tags to an arbitrary field

google.protobuf.Timestamp created_at = 7 [(gorm.field).tag.association_jointable_foreignkey = "foobar"];

I'm seeing the output tag generated as expected

CreatedAt *time.Time `gorm:"association_jointable_foreignkey:foobar"`

Can you give more details?

Calebjh avatar Apr 08 '20 21:04 Calebjh

i see, maybe that works well on non-repeated field. this is what i tried:

int32 max_retry = 11 [(gorm.field).tag = {foreignkey:"non_repeated"}];
    repeated SledinData sledin_data = 12 [(gorm.field).tag = {foreignkey:"repeated_field" association_foreignkey:"foobar"}];

and here is what i got

MaxRetry     int32 `gorm:"foreignkey:non_repeated"`
SledinData   []*SledinDataORM `gorm:"foreignkey:SledinBlastIdblast;association_foreignkey:Idblast"`

alkaaf avatar Apr 09 '20 00:04 alkaaf

after i change the plugins.go, i got the right result for both repeated and non repeated. i don't know about the side effect yet.

int32 max_retry = 11 [(gorm.field).tag = {foreignkey:"non_repeated"}];
repeated SledinData sledin_data = 12 [(gorm.field).tag = {foreignkey:"repeated_field" association_foreignkey:"foobar"}];

the result:

MaxRetry     int32 `gorm:"foreignkey:non_repeated"`
SledinData   []*SledinDataORM `gorm:"foreignkey:repeated_field;association_foreignkey:foobar"`

alkaaf avatar Apr 09 '20 00:04 alkaaf