diff --git a/orm/table.go b/orm/table.go index 29c1c0c3..9e86eaee 100644 --- a/orm/table.go +++ b/orm/table.go @@ -95,9 +95,14 @@ type Table struct { func newTable(typ reflect.Type) *Table { t := new(Table) t.Type = typ + name := t.Type.Name() + index := strings.Index(name, "[") + if index > 0 { + name = name[:index] + } t.zeroStruct = reflect.New(t.Type).Elem() - t.TypeName = internal.ToExported(t.Type.Name()) - t.ModelName = internal.Underscore(t.Type.Name()) + t.TypeName = internal.ToExported(name) + t.ModelName = internal.Underscore(name) tableName := tableNameInflector(t.ModelName) t.setName(quoteIdent(tableName)) t.Alias = quoteIdent(t.ModelName) diff --git a/orm/table_test.go b/orm/table_test.go index c01fcd49..285ede5a 100644 --- a/orm/table_test.go +++ b/orm/table_test.go @@ -262,6 +262,23 @@ var _ = Describe("embedding with ignored field", func() { }) }) +type P[T any] struct { + Data T +} + +var _ = Describe("generics model", func() { + var table *orm.Table + + BeforeEach(func() { + strct := reflect.ValueOf(P[string]{}) + table = orm.GetTable(strct.Type()) + }) + It("TypeName and ModelName", func() { + Expect(table.TypeName).To(BeEquivalentTo("P")) + Expect(table.ModelName).To(BeEquivalentTo("p")) + }) +}) + type Nameless struct { tableName struct{} `pg:"_"`