From 8a0397b6e2219909d6b00d258eb7934170058edd Mon Sep 17 00:00:00 2001 From: emileFRT <104196278+emileFRT@users.noreply.github.com> Date: Tue, 2 Apr 2024 09:37:52 +0200 Subject: [PATCH] fix(table): allow alt annotation (#956) Co-authored-by: emileFRT <> --- schema/table.go | 2 +- schema/table_test.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/schema/table.go b/schema/table.go index fd797f6ee..002aafdb2 100644 --- a/schema/table.go +++ b/schema/table.go @@ -913,7 +913,7 @@ func isKnownTableOption(name string) bool { func isKnownFieldOption(name string) bool { switch name { case "column", - "alias", + "alt", "type", "array", "hstore", diff --git a/schema/table_test.go b/schema/table_test.go index 8dceec7ce..fb14e2aa6 100644 --- a/schema/table_test.go +++ b/schema/table_test.go @@ -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) + }) }