Skip to content

Commit

Permalink
fix: scan error #709 (#837)
Browse files Browse the repository at this point in the history
  • Loading branch information
calorie authored Sep 10, 2023
1 parent f652b3d commit b82afa5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion internal/dbtest/orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ func testBookRelations(t *testing.T, db *bun.DB) {
Relation("Author.Avatar").
Relation("Editor").
Relation("Editor.Avatar").
Relation("Genres").
Relation("Genres", func(q *bun.SelectQuery) *bun.SelectQuery {
return q.Column("id", "name", "genre__rating")
}).
Relation("Comments").
Relation("Translations", func(q *bun.SelectQuery) *bun.SelectQuery {
return q.Order("id")
Expand Down
7 changes: 6 additions & 1 deletion relation_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,12 @@ func (j *relationJoin) m2mQuery(q *SelectQuery) *SelectQuery {
baseTable := j.BaseModel.Table()

if j.Relation.M2MTable != nil {
q = q.ColumnExpr(string(j.Relation.M2MTable.SQLAlias) + ".*")
fields := append(j.Relation.M2MBaseFields, j.Relation.M2MJoinFields...)

b := make([]byte, 0, len(fields))
b = appendColumns(b, j.Relation.M2MTable.SQLAlias, fields)

q = q.ColumnExpr(internal.String(b))
}

//nolint
Expand Down

0 comments on commit b82afa5

Please sign in to comment.