Skip to content

Commit

Permalink
bugfix for update
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardLindhout committed Dec 18, 2021
1 parent 2e6e352 commit 70d4bbd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
42 changes: 22 additions & 20 deletions convert_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ type Field struct { //nolint:maligned
ConvertConfig ConvertConfig
Enum *Enum
// relation stuff
IsRelation bool
IsObject bool
IsRelation bool
IsRelationAndNotForeignKey bool
IsObject bool
// boiler relation stuff is inside this field
BoilerField BoilerField
// graphql relation ship can be found here
Expand Down Expand Up @@ -522,24 +523,25 @@ func enhanceModelsWithFields(enums []*Enum, schema *ast.Schema, cfg *config.Conf

enum := findEnum(enums, shortType)
field := &Field{
Name: name,
JSONName: jsonName,
Type: shortType,
TypeWithoutPointer: strings.Replace(strings.TrimPrefix(shortType, "*"), ".", "Dot", -1),
BoilerField: boilerField,
IsNumberID: isNumberID,
IsPrimaryID: isPrimaryID,
IsPrimaryNumberID: isPrimaryNumberID,
IsPrimaryStringID: isPrimaryStringID,
IsRelation: boilerField.IsRelation,
IsObject: isObject,
IsOr: strings.EqualFold(name, "or"),
IsAnd: strings.EqualFold(name, "and"),
IsPlural: IsPlural(name),
PluralName: Plural(name),
OriginalType: typ,
Description: field.Description,
Enum: enum,
Name: name,
JSONName: jsonName,
Type: shortType,
TypeWithoutPointer: strings.Replace(strings.TrimPrefix(shortType, "*"), ".", "Dot", -1),
BoilerField: boilerField,
IsNumberID: isNumberID,
IsPrimaryID: isPrimaryID,
IsPrimaryNumberID: isPrimaryNumberID,
IsPrimaryStringID: isPrimaryStringID,
IsRelation: boilerField.IsRelation,
IsRelationAndNotForeignKey: boilerField.IsRelation && !strings.HasSuffix(strings.ToLower(name), "id"),
IsObject: isObject,
IsOr: strings.EqualFold(name, "or"),
IsAnd: strings.EqualFold(name, "and"),
IsPlural: IsPlural(name),
PluralName: Plural(name),
OriginalType: typ,
Description: field.Description,
Enum: enum,
}
field.ConvertConfig = getConvertConfig(enums, m, field)
m.Fields = append(m.Fields, field)
Expand Down
11 changes: 7 additions & 4 deletions template_files/generated_convert_input.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@ import (
modelM := {{ $.Backend.PackageName }}.M{}
for key := range input {
switch key {
{{ range $field := .Fields -}}
case "{{ $field.JSONName }}":
modelM[{{ $.Backend.PackageName }}.{{ $model.BoilerModel.Name }}Columns.{{- $field.BoilerField.Name }}] = model.{{ $field.Name }}
{{ end -}}
{{ range $field := .Fields }}
{{ if $field.IsRelationAndNotForeignKey}}
{{ else }}
case "{{ $field.JSONName }}":
modelM[{{ $.Backend.PackageName }}.{{ $model.BoilerModel.Name }}Columns.{{- $field.BoilerField.Name }}] = model.{{ $field.Name }}
{{ end }}
{{ end }}
}
}
return modelM
Expand Down

0 comments on commit 70d4bbd

Please sign in to comment.