We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi!
I'm posting this issue mostly to help others that are facing the same issue, as the workaround described below works well.
Example model:
syntax = "proto3"; option go_package = "github.com/jhberges/dummy"; package dummy; import "options/gorm.proto"; message Parent { option (gorm.opts) = { ormable: true }; string id = 1 [(gorm.field).tag = {type: "uuid"; primary_key: true; default: "uuid_generate_v4()"}]; } message Child { option (gorm.opts) = { ormable: true }; Parent father = 1 [(gorm.field) = {belongs_to: {foreignkey:"father_fk", foreignkey_tag: {unique_index:"idx_unique_parenthood"}}}]; Parent mother = 2 [(gorm.field) = {belongs_to: {foreignkey:"mother_fk", foreignkey_tag: {unique_index:"idx_unique_parenthood"}}}]; }
The plugin will generate the following entity structs from this:
//... type ParentORM struct { Id string `gorm:"type:uuid;primary_key;default:uuid_generate_v4()"` } //... type ChildORM struct { Father *ParentORM `gorm:"foreignkey:FatherFk;association_foreignkey:Id"` FatherFk *string `gorm:"unique_index:idx_unique_parenthood"` Mother *ParentORM `gorm:"foreignkey:MotherFk;association_foreignkey:Id"` MotherFk *string `gorm:"unique_index:idx_unique_parenthood"` } //...
The tag ```gorm:"unique_index:..."is silently ignored as it is expectinguniqueIndex`in the annotation. Thus no index is created.
is silently ignored as it is expecting
Workaround Changing the Child to the following works:
Child
message Child { option (gorm.opts) = { ormable: true }; Parent father = 1 [(gorm.field) = {belongs_to: {foreignkey:"father_fk", foreignkey_tag: {index:"idx_unique_parenthood,unique"}}}]; Parent mother = 2 [(gorm.field) = {belongs_to: {foreignkey:"mother_fk", foreignkey_tag: {index:"idx_unique_parenthood,unique"}}}]; }
Generating an ORM struct:
type ChildORM struct { Father *ParentORM `gorm:"foreignkey:FatherFk;association_foreignkey:Id"` FatherFk *string `gorm:"index:idx_unique_parenthood,unique"` Mother *ParentORM `gorm:"foreignkey:MotherFk;association_foreignkey:Id"` MotherFk *string `gorm:"index:idx_unique_parenthood,unique"` }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Hi!
I'm posting this issue mostly to help others that are facing the same issue, as the workaround described below works well.
Example model:
The plugin will generate the following entity structs from this:
The tag ```gorm:"unique_index:..."
is silently ignored as it is expecting
uniqueIndex`in the annotation.Thus no index is created.
Workaround
Changing the
Child
to the following works:Generating an ORM struct:
The text was updated successfully, but these errors were encountered: