// BeforeUpdate is a hook executed before updating blog.
BeforeUpdate is a hook executed before updating blog.
// BeforeUpdate is a hook executed before updating blog .
func (b *Blog) BeforeUpdate(ctx context.Context, db database.DB) error {
	post, err := NRN_Posts.QueryCtx(ctx, db).
		Select("ID").
		Where("BlogID = ?", b.ID).
		OrderBy("-Likes").
		Get()
	if err != nil {
		if !errors.Is(err, query.ErrNoResult) {
			return err
		}
	}
	if post != nil {
		b.TopPost = post
		b.TopPostID = post.ID
	}
	return nil
}
func ( b * Blog ) BeforeUpdate ( ctx context . Context , db database . DB ) error { post , err := NRN_Posts . QueryCtx ( ctx , db ) . Select ( " " ) . Where ( " " , b . ID ) . OrderBy ( " " ) . Get ( ) if err != nil { if ! errors . Is ( err , query . ErrNoResult ) { return err } } if post != nil { b . TopPost = post b . TopPostID = post . ID } return nil }
BeforeUpdate is a hook executed before updating blog.
BeforeUpdate is a hook executed before updating blog .
// Get the most likeable post for given blog and set it to given blog top post. // Check if the error is about that no models were found for given query. // If the post is found set it's value to the top post.