func (bpuo *BlogPostUpdateOne) AddCategories(c ...*Category) *BlogPostUpdateOne {
	ids := make([]int, len(c))
	for i := range c {
		ids[i] = c[i].ID
	}
	return bpuo.AddCategoryIDs(ids...)
}
AddCategories adds the "categories" edges to the Category entity.
package ent
import (
	"context"
	"fmt"
	"entgo.io/contrib/entproto/internal/entprototest/ent/blogpost"
	"entgo.io/contrib/entproto/internal/entprototest/ent/category"
	"entgo.io/contrib/entproto/internal/entprototest/ent/predicate"
	"entgo.io/contrib/entproto/internal/entprototest/ent/user"
	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
)
type BlogPostUpdate struct {
	config
	hooks    []Hook
	mutation *BlogPostMutation
}
func (bpu *BlogPostUpdate) Where(ps ...predicate.BlogPost) *BlogPostUpdate {
	bpu.mutation.Where(ps...)
	return bpu
}
func (bpu *BlogPostUpdate) SetTitle(s string) *BlogPostUpdate {
	bpu.mutation.SetTitle(s)
	return bpu
}
func (bpu *BlogPostUpdate) SetBody(s string) *BlogPostUpdate {
	bpu.mutation.SetBody(s)
	return bpu
}
func (bpu *BlogPostUpdate) SetExternalID(i int) *BlogPostUpdate {
	bpu.mutation.ResetExternalID()
	bpu.mutation.SetExternalID(i)
	return bpu
}
func (bpu *BlogPostUpdate) AddExternalID(i int) *BlogPostUpdate {
	bpu.mutation.AddExternalID(i)
	return bpu
}
func (bpu *BlogPostUpdate) SetAuthorID(id int) *BlogPostUpdate {
	bpu.mutation.SetAuthorID(id)
	return bpu
}
func (bpu *BlogPostUpdate) SetNillableAuthorID(id *int) *BlogPostUpdate {
	if id != nil {
		bpu = bpu.SetAuthorID(*id)
	}
	return bpu
}
func (bpu *BlogPostUpdate) SetAuthor(u *User) *BlogPostUpdate {
	return bpu.SetAuthorID(u.ID)
}
func (bpu *BlogPostUpdate) AddCategoryIDs(ids ...int) *BlogPostUpdate {
	bpu.mutation.AddCategoryIDs(ids...)
	return bpu
}
func (bpu *BlogPostUpdate) AddCategories(c ...*Category) *BlogPostUpdate {
	ids := make([]int, len(c))
	for i := range c {
		ids[i] = c[i].ID
	}
	return bpu.AddCategoryIDs(ids...)
}
func (bpu *BlogPostUpdate) Mutation() *BlogPostMutation {
	return bpu.mutation
}
func (bpu *BlogPostUpdate) ClearAuthor() *BlogPostUpdate {
	bpu.mutation.ClearAuthor()
	return bpu
}
func (bpu *BlogPostUpdate) ClearCategories() *BlogPostUpdate {
	bpu.mutation.ClearCategories()
	return bpu
}
func (bpu *BlogPostUpdate) RemoveCategoryIDs(ids ...int) *BlogPostUpdate {
	bpu.mutation.RemoveCategoryIDs(ids...)
	return bpu
}
func (bpu *BlogPostUpdate) RemoveCategories(c ...*Category) *BlogPostUpdate {
	ids := make([]int, len(c))
	for i := range c {
		ids[i] = c[i].ID
	}
	return bpu.RemoveCategoryIDs(ids...)
}
func (bpu *BlogPostUpdate) Save(ctx context.Context) (int, error) {
	var (
		err      error
		affected int
	)
	if len(bpu.hooks) == 0 {
		affected, err = bpu.sqlSave(ctx)
	} else {
		var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
			mutation, ok := m.(*BlogPostMutation)
			if !ok {
				return nil, fmt.Errorf("unexpected mutation type %T", m)
			}
			bpu.mutation = mutation
			affected, err = bpu.sqlSave(ctx)
			mutation.done = true
			return affected, err
		})
		for i := len(bpu.hooks) - 1; i >= 0; i-- {
			if bpu.hooks[i] == nil {
				return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
			}
			mut = bpu.hooks[i](mut)
		}
		if _, err := mut.Mutate(ctx, bpu.mutation); err != nil {
			return 0, err
		}
	}
	return affected, err
}
func (bpu *BlogPostUpdate) SaveX(ctx context.Context) int {
	affected, err := bpu.Save(ctx)
	if err != nil {
		panic(err)
	}
	return affected
}
func (bpu *BlogPostUpdate) Exec(ctx context.Context) error {
	_, err := bpu.Save(ctx)
	return err
}
func (bpu *BlogPostUpdate) ExecX(ctx context.Context) {
	if err := bpu.Exec(ctx); err != nil {
		panic(err)
	}
}
func (bpu *BlogPostUpdate) sqlSave(ctx context.Context) (n int, err error) {
	_spec := &sqlgraph.UpdateSpec{
		Node: &sqlgraph.NodeSpec{
			Table:   blogpost.Table,
			Columns: blogpost.Columns,
			ID: &sqlgraph.FieldSpec{
				Type:   field.TypeInt,
				Column: blogpost.FieldID,
			},
		},
	}
	if ps := bpu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := bpu.mutation.Title(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: blogpost.FieldTitle,
		})
	}
	if value, ok := bpu.mutation.Body(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: blogpost.FieldBody,
		})
	}
	if value, ok := bpu.mutation.ExternalID(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeInt,
			Value:  value,
			Column: blogpost.FieldExternalID,
		})
	}
	if value, ok := bpu.mutation.AddedExternalID(); ok {
		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
			Type:   field.TypeInt,
			Value:  value,
			Column: blogpost.FieldExternalID,
		})
	}
	if bpu.mutation.AuthorCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   blogpost.AuthorTable,
			Columns: []string{blogpost.AuthorColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeInt,
					Column: user.FieldID,
				},
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := bpu.mutation.AuthorIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   blogpost.AuthorTable,
			Columns: []string{blogpost.AuthorColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeInt,
					Column: user.FieldID,
				},
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if bpu.mutation.CategoriesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   blogpost.CategoriesTable,
			Columns: blogpost.CategoriesPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeInt,
					Column: category.FieldID,
				},
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := bpu.mutation.RemovedCategoriesIDs(); len(nodes) > 0 && !bpu.mutation.CategoriesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   blogpost.CategoriesTable,
			Columns: blogpost.CategoriesPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeInt,
					Column: category.FieldID,
				},
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := bpu.mutation.CategoriesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   blogpost.CategoriesTable,
			Columns: blogpost.CategoriesPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeInt,
					Column: category.FieldID,
				},
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if n, err = sqlgraph.UpdateNodes(ctx, bpu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{blogpost.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{err.Error(), err}
		}
		return 0, err
	}
	return n, nil
}
type BlogPostUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *BlogPostMutation
}
func (bpuo *BlogPostUpdateOne) SetTitle(s string) *BlogPostUpdateOne {
	bpuo.mutation.SetTitle(s)
	return bpuo
}
func (bpuo *BlogPostUpdateOne) SetBody(s string) *BlogPostUpdateOne {
	bpuo.mutation.SetBody(s)
	return bpuo
}
func (bpuo *BlogPostUpdateOne) SetExternalID(i int) *BlogPostUpdateOne {
	bpuo.mutation.ResetExternalID()
	bpuo.mutation.SetExternalID(i)
	return bpuo
}
func (bpuo *BlogPostUpdateOne) AddExternalID(i int) *BlogPostUpdateOne {
	bpuo.mutation.AddExternalID(i)
	return bpuo
}
func (bpuo *BlogPostUpdateOne) SetAuthorID(id int) *BlogPostUpdateOne {
	bpuo.mutation.SetAuthorID(id)
	return bpuo
}
func (bpuo *BlogPostUpdateOne) SetNillableAuthorID(id *int) *BlogPostUpdateOne {
	if id != nil {
		bpuo = bpuo.SetAuthorID(*id)
	}
	return bpuo
}
func (bpuo *BlogPostUpdateOne) SetAuthor(u *User) *BlogPostUpdateOne {
	return bpuo.SetAuthorID(u.ID)
}
func (bpuo *BlogPostUpdateOne) AddCategoryIDs(ids ...int) *BlogPostUpdateOne {
	bpuo.mutation.AddCategoryIDs(ids...)
	return bpuo
}