uptrace / bun

SQL-first Golang ORM

Home Page:https://bun.uptrace.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

There is not way to perform an inner join for a many relation

nelsonnba opened this issue · comments

having a model relation

type TableA struct {
   ID int
   Name string
   TableBs []*TableB  `bun:"rel:has-many,join:id=table_aid"`
 }
type TableB struct{
  ID int
 TableAID int
  Num int
}

There is no way to perform an inner join for a many relation using ORM Relation, in order to exclude TableA elements without TableB elements that suit one condition.

The following query gets TablaA elements with nil TableBs field, and there is no way to exclude them:

db.NewSelect().Model(tablaA).Relation("TableBs", func(q *bun.SelectQuery) *bun.SelectQuery {
			return q.Where("num = 1")
		})