diff --git a/convert_plugin.go b/convert_plugin.go index ffb8372..d815d5b 100755 --- a/convert_plugin.go +++ b/convert_plugin.go @@ -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 @@ -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) diff --git a/template_files/generated_convert_input.gotpl b/template_files/generated_convert_input.gotpl index 63c0369..9c9921f 100644 --- a/template_files/generated_convert_input.gotpl +++ b/template_files/generated_convert_input.gotpl @@ -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