@@ -122,6 +122,7 @@ func (t *Table) processFields(typ reflect.Type) {
122
122
123
123
names := make (map [string ]struct {})
124
124
embedded := make ([]embeddedField , 0 , 10 )
125
+ ebdStructs := make (map [string ]* structField , 0 )
125
126
126
127
for i , n := 0 , typ .NumField (); i < n ; i ++ {
127
128
sf := typ .Field (i )
@@ -163,6 +164,17 @@ func (t *Table) processFields(typ reflect.Type) {
163
164
subfield : subfield ,
164
165
})
165
166
}
167
+ if len (subtable .StructMap ) > 0 {
168
+ for k , v := range subtable .StructMap {
169
+ // NOTE: conflict Struct name
170
+ if _ , ok := ebdStructs [k ]; ! ok {
171
+ ebdStructs [k ] = & structField {
172
+ Index : makeIndex (sf .Index , v .Index ),
173
+ Table : subtable ,
174
+ }
175
+ }
176
+ }
177
+ }
166
178
167
179
if tagstr != "" {
168
180
tag := tagparser .Parse (tagstr )
@@ -197,6 +209,18 @@ func (t *Table) processFields(typ reflect.Type) {
197
209
subfield : subfield ,
198
210
})
199
211
}
212
+ if len (subtable .StructMap ) > 0 {
213
+ for k , v := range subtable .StructMap {
214
+ // NOTE: conflict Struct name
215
+ k = prefix + k
216
+ if _ , ok := ebdStructs [k ]; ! ok {
217
+ ebdStructs [k ] = & structField {
218
+ Index : makeIndex (sf .Index , v .Index ),
219
+ Table : subtable ,
220
+ }
221
+ }
222
+ }
223
+ }
200
224
continue
201
225
}
202
226
@@ -252,6 +276,15 @@ func (t *Table) processFields(typ reflect.Type) {
252
276
}
253
277
}
254
278
279
+ if len (ebdStructs ) > 0 && t .StructMap == nil {
280
+ t .StructMap = make (map [string ]* structField )
281
+ }
282
+ for name , sfield := range ebdStructs {
283
+ if _ , ok := t .StructMap [name ]; ! ok {
284
+ t .StructMap [name ] = sfield
285
+ }
286
+ }
287
+
255
288
if len (embedded ) > 0 {
256
289
// https://github.com/uptrace/bun/issues/1095
257
290
// < v1.2, all fields follow the order corresponding to the struct
0 commit comments