From 508375b8f2396cb088fd4399a9259584353eb7e5 Mon Sep 17 00:00:00 2001 From: Sam Ward Date: Sat, 25 Dec 2021 12:16:58 -1000 Subject: [PATCH] feat: add anonymous fields with type name --- schema/table.go | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/schema/table.go b/schema/table.go index 88b8d8e25..27b2229dd 100644 --- a/schema/table.go +++ b/schema/table.go @@ -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 {