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
// ToPB runs the BeforeToPB hook if present, converts the fields of this
// object to PB format, runs the AfterToPB hook, then returns the PB object
func (m *UserORM) ToPB(ctx context.Context) (User, error) {
to := User{}
var err error
if prehook, ok := interface{}(m).(UserWithBeforeToPB); ok {
if err = prehook.BeforeToPB(ctx, &to); err != nil {
return to, err
}
}
to.Id = m.Id
to.Gender = Gender(m.Gender)
if posthook, ok := interface{}(m).(UserWithAfterToPB); ok {
err = posthook.AfterToPB(ctx, &to)
}
return to, err
}
to.Gender = Gender(m.Gender)
causes "Cannot use '(Gender)(m. Gender)' (type Gender) as the type *Gender"
to fix this we need to cast it to a pointer Gender type like : to.Gender = (*Gender)(m.Gender)
right now I have to update the generated gorm file maualy each time I re-generate for new fields...
if there is a solution please let me know!
The text was updated successfully, but these errors were encountered:
RomanSter
added a commit
to RomanSter/protoc-gen-gorm
that referenced
this issue
Dec 9, 2024
* added support for optional enums for gorm protoc generator.
based on the issue I opened here:
#280
* return missing line from code that handles b.stringEnums
it seems like the lib does not know how to cast from enum optinal (pointer) fields.
command used to generate the proto:
protoc --go_out=./ --go-grpc_out=. --gorm_out=engine=postgres:./ user.proto
protoc verison:
libprotoc 3.20.3
proto example user.proto:
One of the generated user.pb.gorm.go methods:
to.Gender = Gender(m.Gender)
causes "Cannot use '(Gender)(m. Gender)' (type Gender) as the type *Gender"
to fix this we need to cast it to a pointer Gender type like :
to.Gender = (*Gender)(m.Gender)
right now I have to update the generated gorm file maualy each time I re-generate for new fields...
if there is a solution please let me know!
The text was updated successfully, but these errors were encountered: