@@ -360,7 +360,9 @@ func (t *Table) newField(f reflect.StructField, index []int) *Field {
360
360
return nil
361
361
}
362
362
363
- if isKnownFieldOption (pgTag .Name ) {
363
+ sqlName := internal .Underscore (f .Name )
364
+
365
+ if pgTag .Name != sqlName && isKnownFieldOption (pgTag .Name ) {
364
366
internal .Warn .Printf (
365
367
"%s.%s tag name %q is also an option name; is it a mistake?" ,
366
368
t .TypeName , f .Name , pgTag .Name ,
@@ -374,12 +376,12 @@ func (t *Table) newField(f reflect.StructField, index []int) *Field {
374
376
}
375
377
376
378
skip := pgTag .Name == "-"
377
- if skip || pgTag .Name = = "" {
378
- pgTag . Name = internal . Underscore ( f . Name )
379
+ if ! skip && pgTag .Name ! = "" {
380
+ sqlName = pgTag . Name
379
381
}
380
382
381
383
index = append (index , f .Index ... )
382
- if field := t .getField (pgTag . Name ); field != nil {
384
+ if field := t .getField (sqlName ); field != nil {
383
385
if indexEqual (field .Index , index ) {
384
386
return field
385
387
}
@@ -391,8 +393,8 @@ func (t *Table) newField(f reflect.StructField, index []int) *Field {
391
393
Type : indirectType (f .Type ),
392
394
393
395
GoName : f .Name ,
394
- SQLName : pgTag . Name ,
395
- Column : quoteIdent (pgTag . Name ),
396
+ SQLName : sqlName ,
397
+ Column : quoteIdent (sqlName ),
396
398
397
399
Index : index ,
398
400
}
0 commit comments