Skip to content

Commit

Permalink
fix: reuse tx for relation join (#366)
Browse files Browse the repository at this point in the history
* fix: use Conn() instead of idb method
  • Loading branch information
sbward authored Dec 19, 2021
1 parent 95144dd commit 60bdb1a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions query_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ var (
_ IConn = (*sql.Tx)(nil)
_ IConn = (*DB)(nil)
_ IConn = (*Conn)(nil)
_ IConn = (*Tx)(nil)
_ IConn = (Tx{})
)

// IDB is a common interface for *bun.DB, bun.Conn, and bun.Tx.
// IDB is a common interface for *bun.DB, and bun.Tx.
type IDB interface {
IConn
Dialect() schema.Dialect
Expand All @@ -60,9 +60,8 @@ type IDB interface {
}

var (
_ IConn = (*DB)(nil)
_ IConn = (*Conn)(nil)
_ IConn = (*Tx)(nil)
_ IDB = (*DB)(nil)
_ IDB = Tx{}
)

type baseQuery struct {
Expand Down
4 changes: 2 additions & 2 deletions query_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,9 @@ func (q *SelectQuery) selectJoins(ctx context.Context, joins []relationJoin) err
case schema.HasOneRelation, schema.BelongsToRelation:
err = q.selectJoins(ctx, j.JoinModel.getJoins())
case schema.HasManyRelation:
err = j.selectMany(ctx, q.db.NewSelect())
err = j.selectMany(ctx, q.db.NewSelect().Conn(q.conn))
case schema.ManyToManyRelation:
err = j.selectM2M(ctx, q.db.NewSelect())
err = j.selectM2M(ctx, q.db.NewSelect().Conn(q.conn))
default:
panic("not reached")
}
Expand Down

0 comments on commit 60bdb1a

Please sign in to comment.