File tree 2 files changed +27
-4
lines changed
2 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -259,13 +259,13 @@ func (t *Table) processFields(typ reflect.Type) {
259
259
}
260
260
261
261
for _ , embfield := range embedded {
262
- subfield := embfield .subfield .Clone ()
263
-
264
- if ambiguousNames [subfield .Name ] > 1 &&
265
- ! (! subfield .Tag .IsZero () && ambiguousTags [subfield .Name ] == 1 ) {
262
+ if ambiguousNames [embfield .prefix + embfield .subfield .Name ] > 1 &&
263
+ ! (! embfield .subfield .Tag .IsZero () && ambiguousTags [embfield .prefix + embfield .subfield .Name ] == 1 ) {
266
264
continue // ambiguous embedded field
267
265
}
268
266
267
+ subfield := embfield .subfield .Clone ()
268
+
269
269
subfield .Index = makeIndex (embfield .index , subfield .Index )
270
270
if embfield .prefix != "" {
271
271
subfield .Name = embfield .prefix + subfield .Name
Original file line number Diff line number Diff line change @@ -112,6 +112,29 @@ func TestTable(t *testing.T) {
112
112
require .Equal (t , []int {1 , 0 }, barView .Index )
113
113
})
114
114
115
+ t .Run ("unambiguous embed field" , func (t * testing.T ) {
116
+ type Perms struct {
117
+ View bool
118
+ Create bool
119
+ }
120
+ type Role struct {
121
+ Perms // should be ignore
122
+ Foo Perms `bun:"embed:foo_"`
123
+ View bool
124
+ Create bool
125
+ }
126
+
127
+ table := tables .Get (reflect .TypeFor [* Role ]())
128
+
129
+ view , ok := table .FieldMap ["view" ]
130
+ require .True (t , ok )
131
+ require .Equal (t , []int {2 }, view .Index )
132
+
133
+ fooView , ok := table .FieldMap ["foo_view" ]
134
+ require .True (t , ok )
135
+ require .Equal (t , []int {1 , 0 }, fooView .Index )
136
+ })
137
+
115
138
t .Run ("embedWithUnique" , func (t * testing.T ) {
116
139
type Perms struct {
117
140
View bool
You can’t perform that action at this time.
0 commit comments