I am using uptrace/bun as ORM for golang. I’m joining tables via .Relation() method but while Joining I want to restrict based on conditions. Ex.
query := tx.NewSelect().
Model(xxxx).
Relation("B", func(sq *bun.SelectQuery) *bun.SelectQuery {
return sq.Where("accepted = True")
}).
Relation("C", func(sq *bun.SelectQuery) *bun.SelectQuery {
return sq
})
Further conditions
...
...
Above Bun Generates Query as below
select *
from a
left join b on a.id = b.a_id
left join c on b.id = c.b_id
where a.accepted = true
Further conditions
...
...
...
whereas I need the below
select *
from a
left join b on a.id = b.a_id and b.accepted = true
left join c on b.id = c.b_id
Further conditions
...
...
...