Skip to content

Commit

Permalink
sort enums to prevent merge conflicts and fix problem with enum which…
Browse files Browse the repository at this point in the history
… have underscore in it
  • Loading branch information
RichardLindhout committed Nov 26, 2021
1 parent 470684d commit e281f83
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions convert_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ func GetModelsWithInformation(
// get models based on the schema and sqlboiler structs
models := getModelsFromSchema(cfg.Schema, boilerModels)

// always sort enums the same way to prevent merge conflicts in generated code
sort.Slice(enums, func(i, j int) bool {
return enums[i].Name < enums[j].Name
})

// Now we have all model's let enhance them with fields
enhanceModelsWithFields(enums, cfg.Schema, cfg, models, ignoreTypePrefixes)

Expand Down Expand Up @@ -877,11 +882,13 @@ func findBoilerEnum(enums []*BoilerEnum, graphType string) *BoilerEnum {
func findBoilerEnumValue(enum *BoilerEnum, name string) *BoilerEnumValue {
if enum != nil {
for _, v := range enum.Values {
if strings.EqualFold(strings.TrimPrefix(v.Name, enum.Name), name) {
boilerName := strings.TrimPrefix(v.Name, enum.Name)
frontendName := strings.Replace(name, "_", "", -1)
if strings.EqualFold(boilerName, frontendName) {
return v
}
}
log.Error().Str(enum.Name, name).Msg("could sqlboiler enum value")
log.Error().Str(enum.Name, name).Msg("could not find sqlboiler enum value")
}

return nil
Expand Down

0 comments on commit e281f83

Please sign in to comment.