Skip to content

Commit

Permalink
Merge pull request #1754 from go-pg/fix/tag-mistake-check
Browse files Browse the repository at this point in the history
Improve known tag check
  • Loading branch information
vmihailenco authored Sep 29, 2020
2 parents 55b0ab7 + 302c70f commit 95561fb
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions orm/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
Expand All @@ -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,
}
Expand Down

0 comments on commit 95561fb

Please sign in to comment.