diff --git a/schema/table.go b/schema/table.go index 002aafdb2..0a23156a2 100644 --- a/schema/table.go +++ b/schema/table.go @@ -207,7 +207,7 @@ func (t *Table) processFields( } subtable := newTable(t.dialect, fieldType, seen, canAddr) - for _, subfield := range subtable.Fields { + for _, subfield := range subtable.allFields { embedded = append(embedded, embeddedField{ prefix: prefix, index: sf.Index, diff --git a/schema/table_test.go b/schema/table_test.go index fb14e2aa6..fed1ef2bd 100644 --- a/schema/table_test.go +++ b/schema/table_test.go @@ -134,6 +134,28 @@ func TestTable(t *testing.T) { require.Equal(t, []int{0, 1}, bar.Index) }) + t.Run("embed scanonly prefix", func(t *testing.T) { + type Model1 struct { + Foo string `bun:",scanonly"` + Bar string `bun:",scanonly"` + } + + type Model2 struct { + Baz Model1 `bun:"embed:baz_"` + } + + table := tables.Get(reflect.TypeOf((*Model2)(nil))) + require.Len(t, table.FieldMap, 2) + + foo, ok := table.FieldMap["baz_foo"] + require.True(t, ok) + require.Equal(t, []int{0, 0}, foo.Index) + + bar, ok := table.FieldMap["baz_bar"] + require.True(t, ok) + require.Equal(t, []int{0, 1}, bar.Index) + }) + t.Run("scanonly", func(t *testing.T) { type Model1 struct { Foo string