Skip to content

Commit

Permalink
fixes broken model template (gobuffalo#261)
Browse files Browse the repository at this point in the history
* fixes broken model template

* fixes an issue with the ID field not having a proper tag
  • Loading branch information
markbates authored and stanislas-m committed Oct 2, 2018
1 parent 740070c commit c290a6b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions soda/cmd/generate/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ type attribute struct {
}

func (a attribute) String() string {
if len(a.StructTag) == 0 {
a.StructTag = "json"
}
return fmt.Sprintf("\t%s %s `%s:\"%s\" db:\"%s\"`", a.Name.Pascalize(), a.GoType, a.StructTag, a.Name.Underscore(), a.Name.Underscore())
}

Expand Down
4 changes: 4 additions & 0 deletions soda/cmd/generate/attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ func Test_Attribute_String(t *testing.T) {
exp string
name string
}{
{
name: "id",
exp: "\tID string `json:\"id\" db:\"id\"`",
},
{
name: "user_id",
exp: "\tUserID string `json:\"user_id\" db:\"user_id\"`",
Expand Down
2 changes: 1 addition & 1 deletion soda/cmd/generate/model_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func ({{.char}} *{{.model_name}}) Validate(tx *pop.Connection) (*validate.Errors
{{ if .model.ValidatableAttributes -}}
return validate.Validate(
{{ range $a := .model.ValidatableAttributes -}}
&validators.{{capitalize $a.GoType}}IsPresent{Field: {{$.char}}.{{$a.Name.Camelize}}, Name: "{{$a.Name.Camelize}}"},
&validators.{{capitalize $a.GoType}}IsPresent{Field: {{$.char}}.{{$a.Name.Pascalize}}, Name: "{{$a.Name.Pascalize}}"},
{{end -}}
), nil
{{ else -}}
Expand Down

0 comments on commit c290a6b

Please sign in to comment.