Skip to content

Commit 9527c07

Browse files
author
Miguel Molina
authored
Merge pull request #160 from erizocosmico/fix/kallax-struct-tag
fix kallax struct tag for custom column names
2 parents 3a38e1c + bacdb37 commit 9527c07

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

generator/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,11 +591,11 @@ func (f *Field) SetFields(sf []*Field) {
591591
}
592592

593593
// ColumnName returns the SQL valid column name of the field.
594-
// The struct tag `column` of the field can be use to set the name, otherwise
594+
// The struct tag `kallax` of the field can be use to set the name, otherwise
595595
// is the field name converted to lower snake case.
596596
// If the resultant name is a reserved keyword a _ will be prepended to the name.
597597
func (f *Field) ColumnName() string {
598-
name := f.Tag.Get("column")
598+
name := strings.TrimSpace(strings.Split(f.Tag.Get("kallax"), ",")[0])
599599
if name == "" {
600600
name = toLowerSnakeCase(f.Name)
601601
}

generator/types_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ func (s *FieldSuite) TestColumnName() {
8585
{"", "FooBar", "foo_bar"},
8686
{"", "ID", "id"},
8787
{"", "References", "_references"},
88-
{`column:"foo"`, "Bar", "foo"},
89-
{`column:"References"`, "Bar", "_References"},
90-
{`column:"references"`, "Bar", "_references"},
88+
{`kallax:"foo"`, "Bar", "foo"},
89+
{`kallax:"References"`, "Bar", "_References"},
90+
{`kallax:"references"`, "Bar", "_references"},
9191
}
9292

9393
for _, c := range cases {

0 commit comments

Comments
 (0)