Skip to content

Commit

Permalink
Merge pull request #160 from erizocosmico/fix/kallax-struct-tag
Browse files Browse the repository at this point in the history
fix kallax struct tag for custom column names
  • Loading branch information
Miguel Molina committed May 16, 2017
2 parents 3a38e1c + bacdb37 commit 9527c07
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions generator/types.go
Expand Up @@ -591,11 +591,11 @@ func (f *Field) SetFields(sf []*Field) {
}

// ColumnName returns the SQL valid column name of the field.
// The struct tag `column` of the field can be use to set the name, otherwise
// The struct tag `kallax` of the field can be use to set the name, otherwise
// is the field name converted to lower snake case.
// If the resultant name is a reserved keyword a _ will be prepended to the name.
func (f *Field) ColumnName() string {
name := f.Tag.Get("column")
name := strings.TrimSpace(strings.Split(f.Tag.Get("kallax"), ",")[0])
if name == "" {
name = toLowerSnakeCase(f.Name)
}
Expand Down
6 changes: 3 additions & 3 deletions generator/types_test.go
Expand Up @@ -85,9 +85,9 @@ func (s *FieldSuite) TestColumnName() {
{"", "FooBar", "foo_bar"},
{"", "ID", "id"},
{"", "References", "_references"},
{`column:"foo"`, "Bar", "foo"},
{`column:"References"`, "Bar", "_References"},
{`column:"references"`, "Bar", "_references"},
{`kallax:"foo"`, "Bar", "foo"},
{`kallax:"References"`, "Bar", "_References"},
{`kallax:"references"`, "Bar", "_references"},
}

for _, c := range cases {
Expand Down

0 comments on commit 9527c07

Please sign in to comment.