bun
bun copied to clipboard
There is not way to perform an inner join for a many relation
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")
})