bun
bun copied to clipboard
model doesn't not include `has-many` relation in AfterSelect
Description
model doesn't not include has-many
relation in AfterSelect
type Content struct {
Base
HasCriteria bool `bun:"-"`
Criterias [ ]*Criteria `bun:"rel:has-many,join:id=content_id"`
}
type Criteria struct {
Base
ContentID int
}
var _ bun.AfterSelectHook = (*Gate)(nil)
func (c *Content) AfterSelect(ctx context.Context, query *bun.SelectQuery) error {
if len(gcCriterias) > 0 {
c.HasCriteria = true
}
return nil
}
Query
err = pg.NewSelect().Model(&newGate).Relation("Criterias").Scan(context.Background())