Skip to content

Commit 95561fb

Browse files
authored
Merge pull request #1754 from go-pg/fix/tag-mistake-check
Improve known tag check
2 parents 55b0ab7 + 302c70f commit 95561fb

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

orm/table.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,9 @@ func (t *Table) newField(f reflect.StructField, index []int) *Field {
360360
return nil
361361
}
362362

363-
if isKnownFieldOption(pgTag.Name) {
363+
sqlName := internal.Underscore(f.Name)
364+
365+
if pgTag.Name != sqlName && isKnownFieldOption(pgTag.Name) {
364366
internal.Warn.Printf(
365367
"%s.%s tag name %q is also an option name; is it a mistake?",
366368
t.TypeName, f.Name, pgTag.Name,
@@ -374,12 +376,12 @@ func (t *Table) newField(f reflect.StructField, index []int) *Field {
374376
}
375377

376378
skip := pgTag.Name == "-"
377-
if skip || pgTag.Name == "" {
378-
pgTag.Name = internal.Underscore(f.Name)
379+
if !skip && pgTag.Name != "" {
380+
sqlName = pgTag.Name
379381
}
380382

381383
index = append(index, f.Index...)
382-
if field := t.getField(pgTag.Name); field != nil {
384+
if field := t.getField(sqlName); field != nil {
383385
if indexEqual(field.Index, index) {
384386
return field
385387
}
@@ -391,8 +393,8 @@ func (t *Table) newField(f reflect.StructField, index []int) *Field {
391393
Type: indirectType(f.Type),
392394

393395
GoName: f.Name,
394-
SQLName: pgTag.Name,
395-
Column: quoteIdent(pgTag.Name),
396+
SQLName: sqlName,
397+
Column: quoteIdent(sqlName),
396398

397399
Index: index,
398400
}

0 commit comments

Comments
 (0)