From 302c70f69a5efbea9499705849bdf07b7364dd25 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Tue, 29 Sep 2020 09:19:20 +0300 Subject: [PATCH] Improve known tag check --- orm/table.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/orm/table.go b/orm/table.go index 93ea19a2..564aa918 100644 --- a/orm/table.go +++ b/orm/table.go @@ -360,7 +360,9 @@ func (t *Table) newField(f reflect.StructField, index []int) *Field { return nil } - if isKnownFieldOption(pgTag.Name) { + sqlName := internal.Underscore(f.Name) + + if pgTag.Name != sqlName && isKnownFieldOption(pgTag.Name) { internal.Warn.Printf( "%s.%s tag name %q is also an option name; is it a mistake?", t.TypeName, f.Name, pgTag.Name, @@ -374,12 +376,12 @@ func (t *Table) newField(f reflect.StructField, index []int) *Field { } skip := pgTag.Name == "-" - if skip || pgTag.Name == "" { - pgTag.Name = internal.Underscore(f.Name) + if !skip && pgTag.Name != "" { + sqlName = pgTag.Name } index = append(index, f.Index...) - if field := t.getField(pgTag.Name); field != nil { + if field := t.getField(sqlName); field != nil { if indexEqual(field.Index, index) { return field } @@ -391,8 +393,8 @@ func (t *Table) newField(f reflect.StructField, index []int) *Field { Type: indirectType(f.Type), GoName: f.Name, - SQLName: pgTag.Name, - Column: quoteIdent(pgTag.Name), + SQLName: sqlName, + Column: quoteIdent(sqlName), Index: index, }