Skip to content

Commit

Permalink
feat: accept extend option to allow extending existing models
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Mar 22, 2022
1 parent a99cf89 commit 48b80e4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions internal/dbtest/orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,10 +504,10 @@ func (*Book) BeforeAppendModel(ctx context.Context, query bun.Query) error {
}

// BookWithCommentCount is like Book model, but has additional CommentCount
// field that is used to select data into it. The use of `bun:",inherit"` tag
// is essential here so it inherits internal model properties such as table name.
// field that is used to select data into it. The use of `bun:",extend"` tag
// is essential here.
type BookWithCommentCount struct {
Book `bun:",inherit"`
Book `bun:",extend"`

CommentCount int
}
Expand Down
2 changes: 1 addition & 1 deletion schema/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (t *Table) addFields(typ reflect.Type, prefix string, index []int) {
t.addFields(fieldType, "", withIndex(index, f.Index))

tag := tagparser.Parse(f.Tag.Get("bun"))
if _, inherit := tag.Options["inherit"]; inherit {
if tag.HasOption("inherit") || tag.HasOption("extend") {
embeddedTable := t.dialect.Tables().Ref(fieldType)
t.TypeName = embeddedTable.TypeName
t.SQLName = embeddedTable.SQLName
Expand Down

0 comments on commit 48b80e4

Please sign in to comment.