Skip to content

Commit

Permalink
fix(table): allow alt annotation (#956)
Browse files Browse the repository at this point in the history
Co-authored-by: emileFRT <>
  • Loading branch information
emileFRT authored Apr 2, 2024
1 parent 921b15b commit 8a0397b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion schema/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ func isKnownTableOption(name string) bool {
func isKnownFieldOption(name string) bool {
switch name {
case "column",
"alias",
"alt",
"type",
"array",
"hstore",
Expand Down
19 changes: 19 additions & 0 deletions schema/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,23 @@ func TestTable(t *testing.T) {
require.Equal(t, []int{2, 0}, id.Index)
}
})

t.Run("alternative name", func(t *testing.T) {
type ModelTest struct {
Model
Foo string `bun:"alt:alt_name"`
}

table := tables.Get(reflect.TypeOf((*ModelTest)(nil)))

foo, ok := table.FieldMap["foo"]
require.True(t, ok)
require.Equal(t, []int{1}, foo.Index)

foo2, ok := table.FieldMap["alt_name"]
require.True(t, ok)
require.Equal(t, []int{1}, foo2.Index)

require.Equal(t, table.FieldMap["foo"].SQLName, table.FieldMap["alt_name"].SQLName)
})
}

0 comments on commit 8a0397b

Please sign in to comment.