bun icon indicating copy to clipboard operation
bun copied to clipboard

model doesn't not include `has-many` relation in AfterSelect

Open TheDhejavu opened this issue 1 year ago • 1 comments

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())

TheDhejavu avatar Jun 15 '23 01:06 TheDhejavu