diff options
Diffstat (limited to 'vendor/github.com/uptrace/bun/schema/table.go')
-rw-r--r-- | vendor/github.com/uptrace/bun/schema/table.go | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/vendor/github.com/uptrace/bun/schema/table.go b/vendor/github.com/uptrace/bun/schema/table.go index 642881087..823d4c69f 100644 --- a/vendor/github.com/uptrace/bun/schema/table.go +++ b/vendor/github.com/uptrace/bun/schema/table.go @@ -285,8 +285,8 @@ func (t *Table) processBaseModelField(f reflect.StructField) { if isKnownTableOption(tag.Name) { internal.Warn.Printf( - "%s.%s tag name %q is also an option name; is it a mistake?", - t.TypeName, f.Name, tag.Name, + "%s.%s tag name %q is also an option name, is it a mistake? Try table:%s.", + t.TypeName, f.Name, tag.Name, tag.Name, ) } @@ -300,6 +300,10 @@ func (t *Table) processBaseModelField(f reflect.StructField) { t.setName(tag.Name) } + if s, ok := tag.Option("table"); ok { + t.setName(s) + } + if s, ok := tag.Option("select"); ok { t.SQLNameForSelects = t.quoteTableName(s) } @@ -312,19 +316,23 @@ func (t *Table) processBaseModelField(f reflect.StructField) { //nolint func (t *Table) newField(f reflect.StructField, index []int) *Field { + sqlName := internal.Underscore(f.Name) tag := tagparser.Parse(f.Tag.Get("bun")) - sqlName := internal.Underscore(f.Name) if tag.Name != "" && tag.Name != sqlName { if isKnownFieldOption(tag.Name) { internal.Warn.Printf( - "%s.%s tag name %q is also an option name; is it a mistake?", - t.TypeName, f.Name, tag.Name, + "%s.%s tag name %q is also an option name, is it a mistake? Try column:%s.", + t.TypeName, f.Name, tag.Name, tag.Name, ) } sqlName = tag.Name } + if s, ok := tag.Option("column"); ok { + sqlName = s + } + for name := range tag.Options { if !isKnownFieldOption(name) { internal.Warn.Printf("%s.%s has unknown tag option: %q", t.TypeName, f.Name, name) @@ -854,7 +862,7 @@ func appendNew(dst []int, src ...int) []int { func isKnownTableOption(name string) bool { switch name { - case "alias", "select": + case "table", "alias", "select": return true } return false @@ -862,7 +870,8 @@ func isKnownTableOption(name string) bool { func isKnownFieldOption(name string) bool { switch name { - case "alias", + case "column", + "alias", "type", "array", "hstore", |