Skip to content

Commit

Permalink
feat: add anonymous fields with type name
Browse files Browse the repository at this point in the history
  • Loading branch information
sbward committed Dec 25, 2021
1 parent 509c555 commit 508375b
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions schema/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,23 +251,21 @@ func (t *Table) addFields(typ reflect.Type, prefix string, index []int) {
}

fieldType := indirectType(f.Type)
if fieldType.Kind() != reflect.Struct {
if fieldType.Kind() == reflect.Struct {
t.addFields(fieldType, "", withIndex(index, f.Index))

tag := tagparser.Parse(f.Tag.Get("bun"))
if _, inherit := tag.Options["inherit"]; inherit {
embeddedTable := t.dialect.Tables().Ref(fieldType)
t.TypeName = embeddedTable.TypeName
t.SQLName = embeddedTable.SQLName
t.SQLNameForSelects = embeddedTable.SQLNameForSelects
t.Alias = embeddedTable.Alias
t.SQLAlias = embeddedTable.SQLAlias
t.ModelName = embeddedTable.ModelName
}
continue
}
t.addFields(fieldType, "", withIndex(index, f.Index))

tag := tagparser.Parse(f.Tag.Get("bun"))
if _, inherit := tag.Options["inherit"]; inherit {
embeddedTable := t.dialect.Tables().Ref(fieldType)
t.TypeName = embeddedTable.TypeName
t.SQLName = embeddedTable.SQLName
t.SQLNameForSelects = embeddedTable.SQLNameForSelects
t.Alias = embeddedTable.Alias
t.SQLAlias = embeddedTable.SQLAlias
t.ModelName = embeddedTable.ModelName
}

continue
}

if field := t.newField(f, prefix, index); field != nil {
Expand Down

0 comments on commit 508375b

Please sign in to comment.