// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"formulago/data/ent/menu"
	"formulago/data/ent/menuparam"
	"formulago/data/ent/predicate"
	"formulago/data/ent/role"
	"time"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
)

// MenuUpdate is the builder for updating Menu entities.
type MenuUpdate struct {
	config
	hooks    []Hook
	mutation *MenuMutation
}

// Where appends a list predicates to the MenuUpdate builder.
func (mu *MenuUpdate) Where(ps ...predicate.Menu) *MenuUpdate {
	mu.mutation.Where(ps...)
	return mu
}

// SetUpdatedAt sets the "updated_at" field.
func (mu *MenuUpdate) SetUpdatedAt(t time.Time) *MenuUpdate {
	mu.mutation.SetUpdatedAt(t)
	return mu
}

// SetParentID sets the "parent_id" field.
func (mu *MenuUpdate) SetParentID(u uint64) *MenuUpdate {
	mu.mutation.SetParentID(u)
	return mu
}

// SetNillableParentID sets the "parent_id" field if the given value is not nil.
func (mu *MenuUpdate) SetNillableParentID(u *uint64) *MenuUpdate {
	if u != nil {
		mu.SetParentID(*u)
	}
	return mu
}

// ClearParentID clears the value of the "parent_id" field.
func (mu *MenuUpdate) ClearParentID() *MenuUpdate {
	mu.mutation.ClearParentID()
	return mu
}

// SetMenuLevel sets the "menu_level" field.
func (mu *MenuUpdate) SetMenuLevel(u uint32) *MenuUpdate {
	mu.mutation.ResetMenuLevel()
	mu.mutation.SetMenuLevel(u)
	return mu
}

// AddMenuLevel adds u to the "menu_level" field.
func (mu *MenuUpdate) AddMenuLevel(u int32) *MenuUpdate {
	mu.mutation.AddMenuLevel(u)
	return mu
}

// SetMenuType sets the "menu_type" field.
func (mu *MenuUpdate) SetMenuType(u uint32) *MenuUpdate {
	mu.mutation.ResetMenuType()
	mu.mutation.SetMenuType(u)
	return mu
}

// AddMenuType adds u to the "menu_type" field.
func (mu *MenuUpdate) AddMenuType(u int32) *MenuUpdate {
	mu.mutation.AddMenuType(u)
	return mu
}

// SetPath sets the "path" field.
func (mu *MenuUpdate) SetPath(s string) *MenuUpdate {
	mu.mutation.SetPath(s)
	return mu
}

// SetNillablePath sets the "path" field if the given value is not nil.
func (mu *MenuUpdate) SetNillablePath(s *string) *MenuUpdate {
	if s != nil {
		mu.SetPath(*s)
	}
	return mu
}

// ClearPath clears the value of the "path" field.
func (mu *MenuUpdate) ClearPath() *MenuUpdate {
	mu.mutation.ClearPath()
	return mu
}

// SetName sets the "name" field.
func (mu *MenuUpdate) SetName(s string) *MenuUpdate {
	mu.mutation.SetName(s)
	return mu
}

// SetRedirect sets the "redirect" field.
func (mu *MenuUpdate) SetRedirect(s string) *MenuUpdate {
	mu.mutation.SetRedirect(s)
	return mu
}

// SetNillableRedirect sets the "redirect" field if the given value is not nil.
func (mu *MenuUpdate) SetNillableRedirect(s *string) *MenuUpdate {
	if s != nil {
		mu.SetRedirect(*s)
	}
	return mu
}

// ClearRedirect clears the value of the "redirect" field.
func (mu *MenuUpdate) ClearRedirect() *MenuUpdate {
	mu.mutation.ClearRedirect()
	return mu
}

// SetComponent sets the "component" field.
func (mu *MenuUpdate) SetComponent(s string) *MenuUpdate {
	mu.mutation.SetComponent(s)
	return mu
}

// SetNillableComponent sets the "component" field if the given value is not nil.
func (mu *MenuUpdate) SetNillableComponent(s *string) *MenuUpdate {
	if s != nil {
		mu.SetComponent(*s)
	}
	return mu
}

// ClearComponent clears the value of the "component" field.
func (mu *MenuUpdate) ClearComponent() *MenuUpdate {
	mu.mutation.ClearComponent()
	return mu
}

// SetOrderNo sets the "order_no" field.
func (mu *MenuUpdate) SetOrderNo(u uint32) *MenuUpdate {
	mu.mutation.ResetOrderNo()
	mu.mutation.SetOrderNo(u)
	return mu
}

// SetNillableOrderNo sets the "order_no" field if the given value is not nil.
func (mu *MenuUpdate) SetNillableOrderNo(u *uint32) *MenuUpdate {
	if u != nil {
		mu.SetOrderNo(*u)
	}
	return mu
}

// AddOrderNo adds u to the "order_no" field.
func (mu *MenuUpdate) AddOrderNo(u int32) *MenuUpdate {
	mu.mutation.AddOrderNo(u)
	return mu
}

// SetDisabled sets the "disabled" field.
func (mu *MenuUpdate) SetDisabled(b bool) *MenuUpdate {
	mu.mutation.SetDisabled(b)
	return mu
}

// SetNillableDisabled sets the "disabled" field if the given value is not nil.
func (mu *MenuUpdate) SetNillableDisabled(b *bool) *MenuUpdate {
	if b != nil {
		mu.SetDisabled(*b)
	}
	return mu
}

// ClearDisabled clears the value of the "disabled" field.
func (mu *MenuUpdate) ClearDisabled() *MenuUpdate {
	mu.mutation.ClearDisabled()
	return mu
}

// SetTitle sets the "title" field.
func (mu *MenuUpdate) SetTitle(s string) *MenuUpdate {
	mu.mutation.SetTitle(s)
	return mu
}

// SetIcon sets the "icon" field.
func (mu *MenuUpdate) SetIcon(s string) *MenuUpdate {
	mu.mutation.SetIcon(s)
	return mu
}

// SetHideMenu sets the "hide_menu" field.
func (mu *MenuUpdate) SetHideMenu(b bool) *MenuUpdate {
	mu.mutation.SetHideMenu(b)
	return mu
}

// SetNillableHideMenu sets the "hide_menu" field if the given value is not nil.
func (mu *MenuUpdate) SetNillableHideMenu(b *bool) *MenuUpdate {
	if b != nil {
		mu.SetHideMenu(*b)
	}
	return mu
}

// ClearHideMenu clears the value of the "hide_menu" field.
func (mu *MenuUpdate) ClearHideMenu() *MenuUpdate {
	mu.mutation.ClearHideMenu()
	return mu
}

// SetHideBreadcrumb sets the "hide_breadcrumb" field.
func (mu *MenuUpdate) SetHideBreadcrumb(b bool) *MenuUpdate {
	mu.mutation.SetHideBreadcrumb(b)
	return mu
}

// SetNillableHideBreadcrumb sets the "hide_breadcrumb" field if the given value is not nil.
func (mu *MenuUpdate) SetNillableHideBreadcrumb(b *bool) *MenuUpdate {
	if b != nil {
		mu.SetHideBreadcrumb(*b)
	}
	return mu
}

// ClearHideBreadcrumb clears the value of the "hide_breadcrumb" field.
func (mu *MenuUpdate) ClearHideBreadcrumb() *MenuUpdate {
	mu.mutation.ClearHideBreadcrumb()
	return mu
}

// SetCurrentActiveMenu sets the "current_active_menu" field.
func (mu *MenuUpdate) SetCurrentActiveMenu(s string) *MenuUpdate {
	mu.mutation.SetCurrentActiveMenu(s)
	return mu
}

// SetNillableCurrentActiveMenu sets the "current_active_menu" field if the given value is not nil.
func (mu *MenuUpdate) SetNillableCurrentActiveMenu(s *string) *MenuUpdate {
	if s != nil {
		mu.SetCurrentActiveMenu(*s)
	}
	return mu
}

// ClearCurrentActiveMenu clears the value of the "current_active_menu" field.
func (mu *MenuUpdate) ClearCurrentActiveMenu() *MenuUpdate {
	mu.mutation.ClearCurrentActiveMenu()
	return mu
}

// SetIgnoreKeepAlive sets the "ignore_keep_alive" field.
func (mu *MenuUpdate) SetIgnoreKeepAlive(b bool) *MenuUpdate {
	mu.mutation.SetIgnoreKeepAlive(b)
	return mu
}

// SetNillableIgnoreKeepAlive sets the "ignore_keep_alive" field if the given value is not nil.
func (mu *MenuUpdate) SetNillableIgnoreKeepAlive(b *bool) *MenuUpdate {
	if b != nil {
		mu.SetIgnoreKeepAlive(*b)
	}
	return mu
}

// ClearIgnoreKeepAlive clears the value of the "ignore_keep_alive" field.
func (mu *MenuUpdate) ClearIgnoreKeepAlive() *MenuUpdate {
	mu.mutation.ClearIgnoreKeepAlive()
	return mu
}

// SetHideTab sets the "hide_tab" field.
func (mu *MenuUpdate) SetHideTab(b bool) *MenuUpdate {
	mu.mutation.SetHideTab(b)
	return mu
}

// SetNillableHideTab sets the "hide_tab" field if the given value is not nil.
func (mu *MenuUpdate) SetNillableHideTab(b *bool) *MenuUpdate {
	if b != nil {
		mu.SetHideTab(*b)
	}
	return mu
}

// ClearHideTab clears the value of the "hide_tab" field.
func (mu *MenuUpdate) ClearHideTab() *MenuUpdate {
	mu.mutation.ClearHideTab()
	return mu
}

// SetFrameSrc sets the "frame_src" field.
func (mu *MenuUpdate) SetFrameSrc(s string) *MenuUpdate {
	mu.mutation.SetFrameSrc(s)
	return mu
}

// SetNillableFrameSrc sets the "frame_src" field if the given value is not nil.
func (mu *MenuUpdate) SetNillableFrameSrc(s *string) *MenuUpdate {
	if s != nil {
		mu.SetFrameSrc(*s)
	}
	return mu
}

// ClearFrameSrc clears the value of the "frame_src" field.
func (mu *MenuUpdate) ClearFrameSrc() *MenuUpdate {
	mu.mutation.ClearFrameSrc()
	return mu
}

// SetCarryParam sets the "carry_param" field.
func (mu *MenuUpdate) SetCarryParam(b bool) *MenuUpdate {
	mu.mutation.SetCarryParam(b)
	return mu
}

// SetNillableCarryParam sets the "carry_param" field if the given value is not nil.
func (mu *MenuUpdate) SetNillableCarryParam(b *bool) *MenuUpdate {
	if b != nil {
		mu.SetCarryParam(*b)
	}
	return mu
}

// ClearCarryParam clears the value of the "carry_param" field.
func (mu *MenuUpdate) ClearCarryParam() *MenuUpdate {
	mu.mutation.ClearCarryParam()
	return mu
}

// SetHideChildrenInMenu sets the "hide_children_in_menu" field.
func (mu *MenuUpdate) SetHideChildrenInMenu(b bool) *MenuUpdate {
	mu.mutation.SetHideChildrenInMenu(b)
	return mu
}

// SetNillableHideChildrenInMenu sets the "hide_children_in_menu" field if the given value is not nil.
func (mu *MenuUpdate) SetNillableHideChildrenInMenu(b *bool) *MenuUpdate {
	if b != nil {
		mu.SetHideChildrenInMenu(*b)
	}
	return mu
}

// ClearHideChildrenInMenu clears the value of the "hide_children_in_menu" field.
func (mu *MenuUpdate) ClearHideChildrenInMenu() *MenuUpdate {
	mu.mutation.ClearHideChildrenInMenu()
	return mu
}

// SetAffix sets the "affix" field.
func (mu *MenuUpdate) SetAffix(b bool) *MenuUpdate {
	mu.mutation.SetAffix(b)
	return mu
}

// SetNillableAffix sets the "affix" field if the given value is not nil.
func (mu *MenuUpdate) SetNillableAffix(b *bool) *MenuUpdate {
	if b != nil {
		mu.SetAffix(*b)
	}
	return mu
}

// ClearAffix clears the value of the "affix" field.
func (mu *MenuUpdate) ClearAffix() *MenuUpdate {
	mu.mutation.ClearAffix()
	return mu
}

// SetDynamicLevel sets the "dynamic_level" field.
func (mu *MenuUpdate) SetDynamicLevel(u uint32) *MenuUpdate {
	mu.mutation.ResetDynamicLevel()
	mu.mutation.SetDynamicLevel(u)
	return mu
}

// SetNillableDynamicLevel sets the "dynamic_level" field if the given value is not nil.
func (mu *MenuUpdate) SetNillableDynamicLevel(u *uint32) *MenuUpdate {
	if u != nil {
		mu.SetDynamicLevel(*u)
	}
	return mu
}

// AddDynamicLevel adds u to the "dynamic_level" field.
func (mu *MenuUpdate) AddDynamicLevel(u int32) *MenuUpdate {
	mu.mutation.AddDynamicLevel(u)
	return mu
}

// ClearDynamicLevel clears the value of the "dynamic_level" field.
func (mu *MenuUpdate) ClearDynamicLevel() *MenuUpdate {
	mu.mutation.ClearDynamicLevel()
	return mu
}

// SetRealPath sets the "real_path" field.
func (mu *MenuUpdate) SetRealPath(s string) *MenuUpdate {
	mu.mutation.SetRealPath(s)
	return mu
}

// SetNillableRealPath sets the "real_path" field if the given value is not nil.
func (mu *MenuUpdate) SetNillableRealPath(s *string) *MenuUpdate {
	if s != nil {
		mu.SetRealPath(*s)
	}
	return mu
}

// ClearRealPath clears the value of the "real_path" field.
func (mu *MenuUpdate) ClearRealPath() *MenuUpdate {
	mu.mutation.ClearRealPath()
	return mu
}

// AddRoleIDs adds the "roles" edge to the Role entity by IDs.
func (mu *MenuUpdate) AddRoleIDs(ids ...uint64) *MenuUpdate {
	mu.mutation.AddRoleIDs(ids...)
	return mu
}

// AddRoles adds the "roles" edges to the Role entity.
func (mu *MenuUpdate) AddRoles(r ...*Role) *MenuUpdate {
	ids := make([]uint64, len(r))
	for i := range r {
		ids[i] = r[i].ID
	}
	return mu.AddRoleIDs(ids...)
}

// SetParent sets the "parent" edge to the Menu entity.
func (mu *MenuUpdate) SetParent(m *Menu) *MenuUpdate {
	return mu.SetParentID(m.ID)
}

// AddChildIDs adds the "children" edge to the Menu entity by IDs.
func (mu *MenuUpdate) AddChildIDs(ids ...uint64) *MenuUpdate {
	mu.mutation.AddChildIDs(ids...)
	return mu
}

// AddChildren adds the "children" edges to the Menu entity.
func (mu *MenuUpdate) AddChildren(m ...*Menu) *MenuUpdate {
	ids := make([]uint64, len(m))
	for i := range m {
		ids[i] = m[i].ID
	}
	return mu.AddChildIDs(ids...)
}

// AddParamIDs adds the "params" edge to the MenuParam entity by IDs.
func (mu *MenuUpdate) AddParamIDs(ids ...uint64) *MenuUpdate {
	mu.mutation.AddParamIDs(ids...)
	return mu
}

// AddParams adds the "params" edges to the MenuParam entity.
func (mu *MenuUpdate) AddParams(m ...*MenuParam) *MenuUpdate {
	ids := make([]uint64, len(m))
	for i := range m {
		ids[i] = m[i].ID
	}
	return mu.AddParamIDs(ids...)
}

// Mutation returns the MenuMutation object of the builder.
func (mu *MenuUpdate) Mutation() *MenuMutation {
	return mu.mutation
}

// ClearRoles clears all "roles" edges to the Role entity.
func (mu *MenuUpdate) ClearRoles() *MenuUpdate {
	mu.mutation.ClearRoles()
	return mu
}

// RemoveRoleIDs removes the "roles" edge to Role entities by IDs.
func (mu *MenuUpdate) RemoveRoleIDs(ids ...uint64) *MenuUpdate {
	mu.mutation.RemoveRoleIDs(ids...)
	return mu
}

// RemoveRoles removes "roles" edges to Role entities.
func (mu *MenuUpdate) RemoveRoles(r ...*Role) *MenuUpdate {
	ids := make([]uint64, len(r))
	for i := range r {
		ids[i] = r[i].ID
	}
	return mu.RemoveRoleIDs(ids...)
}

// ClearParent clears the "parent" edge to the Menu entity.
func (mu *MenuUpdate) ClearParent() *MenuUpdate {
	mu.mutation.ClearParent()
	return mu
}

// ClearChildren clears all "children" edges to the Menu entity.
func (mu *MenuUpdate) ClearChildren() *MenuUpdate {
	mu.mutation.ClearChildren()
	return mu
}

// RemoveChildIDs removes the "children" edge to Menu entities by IDs.
func (mu *MenuUpdate) RemoveChildIDs(ids ...uint64) *MenuUpdate {
	mu.mutation.RemoveChildIDs(ids...)
	return mu
}

// RemoveChildren removes "children" edges to Menu entities.
func (mu *MenuUpdate) RemoveChildren(m ...*Menu) *MenuUpdate {
	ids := make([]uint64, len(m))
	for i := range m {
		ids[i] = m[i].ID
	}
	return mu.RemoveChildIDs(ids...)
}

// ClearParams clears all "params" edges to the MenuParam entity.
func (mu *MenuUpdate) ClearParams() *MenuUpdate {
	mu.mutation.ClearParams()
	return mu
}

// RemoveParamIDs removes the "params" edge to MenuParam entities by IDs.
func (mu *MenuUpdate) RemoveParamIDs(ids ...uint64) *MenuUpdate {
	mu.mutation.RemoveParamIDs(ids...)
	return mu
}

// RemoveParams removes "params" edges to MenuParam entities.
func (mu *MenuUpdate) RemoveParams(m ...*MenuParam) *MenuUpdate {
	ids := make([]uint64, len(m))
	for i := range m {
		ids[i] = m[i].ID
	}
	return mu.RemoveParamIDs(ids...)
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (mu *MenuUpdate) Save(ctx context.Context) (int, error) {
	mu.defaults()
	return withHooks[int, MenuMutation](ctx, mu.sqlSave, mu.mutation, mu.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (mu *MenuUpdate) SaveX(ctx context.Context) int {
	affected, err := mu.Save(ctx)
	if err != nil {
		panic(err)
	}
	return affected
}

// Exec executes the query.
func (mu *MenuUpdate) Exec(ctx context.Context) error {
	_, err := mu.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (mu *MenuUpdate) ExecX(ctx context.Context) {
	if err := mu.Exec(ctx); err != nil {
		panic(err)
	}
}

// defaults sets the default values of the builder before save.
func (mu *MenuUpdate) defaults() {
	if _, ok := mu.mutation.UpdatedAt(); !ok {
		v := menu.UpdateDefaultUpdatedAt()
		mu.mutation.SetUpdatedAt(v)
	}
}

func (mu *MenuUpdate) sqlSave(ctx context.Context) (n int, err error) {
	_spec := &sqlgraph.UpdateSpec{
		Node: &sqlgraph.NodeSpec{
			Table:   menu.Table,
			Columns: menu.Columns,
			ID: &sqlgraph.FieldSpec{
				Type:   field.TypeUint64,
				Column: menu.FieldID,
			},
		},
	}
	if ps := mu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := mu.mutation.UpdatedAt(); ok {
		_spec.SetField(menu.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := mu.mutation.MenuLevel(); ok {
		_spec.SetField(menu.FieldMenuLevel, field.TypeUint32, value)
	}
	if value, ok := mu.mutation.AddedMenuLevel(); ok {
		_spec.AddField(menu.FieldMenuLevel, field.TypeUint32, value)
	}
	if value, ok := mu.mutation.MenuType(); ok {
		_spec.SetField(menu.FieldMenuType, field.TypeUint32, value)
	}
	if value, ok := mu.mutation.AddedMenuType(); ok {
		_spec.AddField(menu.FieldMenuType, field.TypeUint32, value)
	}
	if value, ok := mu.mutation.Path(); ok {
		_spec.SetField(menu.FieldPath, field.TypeString, value)
	}
	if mu.mutation.PathCleared() {
		_spec.ClearField(menu.FieldPath, field.TypeString)
	}
	if value, ok := mu.mutation.Name(); ok {
		_spec.SetField(menu.FieldName, field.TypeString, value)
	}
	if value, ok := mu.mutation.Redirect(); ok {
		_spec.SetField(menu.FieldRedirect, field.TypeString, value)
	}
	if mu.mutation.RedirectCleared() {
		_spec.ClearField(menu.FieldRedirect, field.TypeString)
	}
	if value, ok := mu.mutation.Component(); ok {
		_spec.SetField(menu.FieldComponent, field.TypeString, value)
	}
	if mu.mutation.ComponentCleared() {
		_spec.ClearField(menu.FieldComponent, field.TypeString)
	}
	if value, ok := mu.mutation.OrderNo(); ok {
		_spec.SetField(menu.FieldOrderNo, field.TypeUint32, value)
	}
	if value, ok := mu.mutation.AddedOrderNo(); ok {
		_spec.AddField(menu.FieldOrderNo, field.TypeUint32, value)
	}
	if value, ok := mu.mutation.Disabled(); ok {
		_spec.SetField(menu.FieldDisabled, field.TypeBool, value)
	}
	if mu.mutation.DisabledCleared() {
		_spec.ClearField(menu.FieldDisabled, field.TypeBool)
	}
	if value, ok := mu.mutation.Title(); ok {
		_spec.SetField(menu.FieldTitle, field.TypeString, value)
	}
	if value, ok := mu.mutation.Icon(); ok {
		_spec.SetField(menu.FieldIcon, field.TypeString, value)
	}
	if value, ok := mu.mutation.HideMenu(); ok {
		_spec.SetField(menu.FieldHideMenu, field.TypeBool, value)
	}
	if mu.mutation.HideMenuCleared() {
		_spec.ClearField(menu.FieldHideMenu, field.TypeBool)
	}
	if value, ok := mu.mutation.HideBreadcrumb(); ok {
		_spec.SetField(menu.FieldHideBreadcrumb, field.TypeBool, value)
	}
	if mu.mutation.HideBreadcrumbCleared() {
		_spec.ClearField(menu.FieldHideBreadcrumb, field.TypeBool)
	}
	if value, ok := mu.mutation.CurrentActiveMenu(); ok {
		_spec.SetField(menu.FieldCurrentActiveMenu, field.TypeString, value)
	}
	if mu.mutation.CurrentActiveMenuCleared() {
		_spec.ClearField(menu.FieldCurrentActiveMenu, field.TypeString)
	}
	if value, ok := mu.mutation.IgnoreKeepAlive(); ok {
		_spec.SetField(menu.FieldIgnoreKeepAlive, field.TypeBool, value)
	}
	if mu.mutation.IgnoreKeepAliveCleared() {
		_spec.ClearField(menu.FieldIgnoreKeepAlive, field.TypeBool)
	}
	if value, ok := mu.mutation.HideTab(); ok {
		_spec.SetField(menu.FieldHideTab, field.TypeBool, value)
	}
	if mu.mutation.HideTabCleared() {
		_spec.ClearField(menu.FieldHideTab, field.TypeBool)
	}
	if value, ok := mu.mutation.FrameSrc(); ok {
		_spec.SetField(menu.FieldFrameSrc, field.TypeString, value)
	}
	if mu.mutation.FrameSrcCleared() {
		_spec.ClearField(menu.FieldFrameSrc, field.TypeString)
	}
	if value, ok := mu.mutation.CarryParam(); ok {
		_spec.SetField(menu.FieldCarryParam, field.TypeBool, value)
	}
	if mu.mutation.CarryParamCleared() {
		_spec.ClearField(menu.FieldCarryParam, field.TypeBool)
	}
	if value, ok := mu.mutation.HideChildrenInMenu(); ok {
		_spec.SetField(menu.FieldHideChildrenInMenu, field.TypeBool, value)
	}
	if mu.mutation.HideChildrenInMenuCleared() {
		_spec.ClearField(menu.FieldHideChildrenInMenu, field.TypeBool)
	}
	if value, ok := mu.mutation.Affix(); ok {
		_spec.SetField(menu.FieldAffix, field.TypeBool, value)
	}
	if mu.mutation.AffixCleared() {
		_spec.ClearField(menu.FieldAffix, field.TypeBool)
	}
	if value, ok := mu.mutation.DynamicLevel(); ok {
		_spec.SetField(menu.FieldDynamicLevel, field.TypeUint32, value)
	}
	if value, ok := mu.mutation.AddedDynamicLevel(); ok {
		_spec.AddField(menu.FieldDynamicLevel, field.TypeUint32, value)
	}
	if mu.mutation.DynamicLevelCleared() {
		_spec.ClearField(menu.FieldDynamicLevel, field.TypeUint32)
	}
	if value, ok := mu.mutation.RealPath(); ok {
		_spec.SetField(menu.FieldRealPath, field.TypeString, value)
	}
	if mu.mutation.RealPathCleared() {
		_spec.ClearField(menu.FieldRealPath, field.TypeString)
	}
	if mu.mutation.RolesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   menu.RolesTable,
			Columns: menu.RolesPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUint64,
					Column: role.FieldID,
				},
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := mu.mutation.RemovedRolesIDs(); len(nodes) > 0 && !mu.mutation.RolesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   menu.RolesTable,
			Columns: menu.RolesPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUint64,
					Column: role.FieldID,
				},
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := mu.mutation.RolesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   menu.RolesTable,
			Columns: menu.RolesPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUint64,
					Column: role.FieldID,
				},
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if mu.mutation.ParentCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   menu.ParentTable,
			Columns: []string{menu.ParentColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUint64,
					Column: menu.FieldID,
				},
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := mu.mutation.ParentIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   menu.ParentTable,
			Columns: []string{menu.ParentColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUint64,
					Column: menu.FieldID,
				},
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if mu.mutation.ChildrenCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   menu.ChildrenTable,
			Columns: []string{menu.ChildrenColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUint64,
					Column: menu.FieldID,
				},
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := mu.mutation.RemovedChildrenIDs(); len(nodes) > 0 && !mu.mutation.ChildrenCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   menu.ChildrenTable,
			Columns: []string{menu.ChildrenColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUint64,
					Column: menu.FieldID,
				},
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := mu.mutation.ChildrenIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   menu.ChildrenTable,
			Columns: []string{menu.ChildrenColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUint64,
					Column: menu.FieldID,
				},
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if mu.mutation.ParamsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   menu.ParamsTable,
			Columns: []string{menu.ParamsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUint64,
					Column: menuparam.FieldID,
				},
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := mu.mutation.RemovedParamsIDs(); len(nodes) > 0 && !mu.mutation.ParamsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   menu.ParamsTable,
			Columns: []string{menu.ParamsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUint64,
					Column: menuparam.FieldID,
				},
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := mu.mutation.ParamsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   menu.ParamsTable,
			Columns: []string{menu.ParamsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUint64,
					Column: menuparam.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, mu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{menu.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	mu.mutation.done = true
	return n, nil
}

// MenuUpdateOne is the builder for updating a single Menu entity.
type MenuUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *MenuMutation
}

// SetUpdatedAt sets the "updated_at" field.
func (muo *MenuUpdateOne) SetUpdatedAt(t time.Time) *MenuUpdateOne {
	muo.mutation.SetUpdatedAt(t)
	return muo
}

// SetParentID sets the "parent_id" field.
func (muo *MenuUpdateOne) SetParentID(u uint64) *MenuUpdateOne {
	muo.mutation.SetParentID(u)
	return muo
}

// SetNillableParentID sets the "parent_id" field if the given value is not nil.
func (muo *MenuUpdateOne) SetNillableParentID(u *uint64) *MenuUpdateOne {
	if u != nil {
		muo.SetParentID(*u)
	}
	return muo
}

// ClearParentID clears the value of the "parent_id" field.
func (muo *MenuUpdateOne) ClearParentID() *MenuUpdateOne {
	muo.mutation.ClearParentID()
	return muo
}

// SetMenuLevel sets the "menu_level" field.
func (muo *MenuUpdateOne) SetMenuLevel(u uint32) *MenuUpdateOne {
	muo.mutation.ResetMenuLevel()
	muo.mutation.SetMenuLevel(u)
	return muo
}

// AddMenuLevel adds u to the "menu_level" field.
func (muo *MenuUpdateOne) AddMenuLevel(u int32) *MenuUpdateOne {
	muo.mutation.AddMenuLevel(u)
	return muo
}

// SetMenuType sets the "menu_type" field.
func (muo *MenuUpdateOne) SetMenuType(u uint32) *MenuUpdateOne {
	muo.mutation.ResetMenuType()
	muo.mutation.SetMenuType(u)
	return muo
}

// AddMenuType adds u to the "menu_type" field.
func (muo *MenuUpdateOne) AddMenuType(u int32) *MenuUpdateOne {
	muo.mutation.AddMenuType(u)
	return muo
}

// SetPath sets the "path" field.
func (muo *MenuUpdateOne) SetPath(s string) *MenuUpdateOne {
	muo.mutation.SetPath(s)
	return muo
}

// SetNillablePath sets the "path" field if the given value is not nil.
func (muo *MenuUpdateOne) SetNillablePath(s *string) *MenuUpdateOne {
	if s != nil {
		muo.SetPath(*s)
	}
	return muo
}

// ClearPath clears the value of the "path" field.
func (muo *MenuUpdateOne) ClearPath() *MenuUpdateOne {
	muo.mutation.ClearPath()
	return muo
}

// SetName sets the "name" field.
func (muo *MenuUpdateOne) SetName(s string) *MenuUpdateOne {
	muo.mutation.SetName(s)
	return muo
}

// SetRedirect sets the "redirect" field.
func (muo *MenuUpdateOne) SetRedirect(s string) *MenuUpdateOne {
	muo.mutation.SetRedirect(s)
	return muo
}

// SetNillableRedirect sets the "redirect" field if the given value is not nil.
func (muo *MenuUpdateOne) SetNillableRedirect(s *string) *MenuUpdateOne {
	if s != nil {
		muo.SetRedirect(*s)
	}
	return muo
}

// ClearRedirect clears the value of the "redirect" field.
func (muo *MenuUpdateOne) ClearRedirect() *MenuUpdateOne {
	muo.mutation.ClearRedirect()
	return muo
}

// SetComponent sets the "component" field.
func (muo *MenuUpdateOne) SetComponent(s string) *MenuUpdateOne {
	muo.mutation.SetComponent(s)
	return muo
}

// SetNillableComponent sets the "component" field if the given value is not nil.
func (muo *MenuUpdateOne) SetNillableComponent(s *string) *MenuUpdateOne {
	if s != nil {
		muo.SetComponent(*s)
	}
	return muo
}

// ClearComponent clears the value of the "component" field.
func (muo *MenuUpdateOne) ClearComponent() *MenuUpdateOne {
	muo.mutation.ClearComponent()
	return muo
}

// SetOrderNo sets the "order_no" field.
func (muo *MenuUpdateOne) SetOrderNo(u uint32) *MenuUpdateOne {
	muo.mutation.ResetOrderNo()
	muo.mutation.SetOrderNo(u)
	return muo
}

// SetNillableOrderNo sets the "order_no" field if the given value is not nil.
func (muo *MenuUpdateOne) SetNillableOrderNo(u *uint32) *MenuUpdateOne {
	if u != nil {
		muo.SetOrderNo(*u)
	}
	return muo
}

// AddOrderNo adds u to the "order_no" field.
func (muo *MenuUpdateOne) AddOrderNo(u int32) *MenuUpdateOne {
	muo.mutation.AddOrderNo(u)
	return muo
}

// SetDisabled sets the "disabled" field.
func (muo *MenuUpdateOne) SetDisabled(b bool) *MenuUpdateOne {
	muo.mutation.SetDisabled(b)
	return muo
}

// SetNillableDisabled sets the "disabled" field if the given value is not nil.
func (muo *MenuUpdateOne) SetNillableDisabled(b *bool) *MenuUpdateOne {
	if b != nil {
		muo.SetDisabled(*b)
	}
	return muo
}

// ClearDisabled clears the value of the "disabled" field.
func (muo *MenuUpdateOne) ClearDisabled() *MenuUpdateOne {
	muo.mutation.ClearDisabled()
	return muo
}

// SetTitle sets the "title" field.
func (muo *MenuUpdateOne) SetTitle(s string) *MenuUpdateOne {
	muo.mutation.SetTitle(s)
	return muo
}

// SetIcon sets the "icon" field.
func (muo *MenuUpdateOne) SetIcon(s string) *MenuUpdateOne {
	muo.mutation.SetIcon(s)
	return muo
}

// SetHideMenu sets the "hide_menu" field.
func (muo *MenuUpdateOne) SetHideMenu(b bool) *MenuUpdateOne {
	muo.mutation.SetHideMenu(b)
	return muo
}

// SetNillableHideMenu sets the "hide_menu" field if the given value is not nil.
func (muo *MenuUpdateOne) SetNillableHideMenu(b *bool) *MenuUpdateOne {
	if b != nil {
		muo.SetHideMenu(*b)
	}
	return muo
}

// ClearHideMenu clears the value of the "hide_menu" field.
func (muo *MenuUpdateOne) ClearHideMenu() *MenuUpdateOne {
	muo.mutation.ClearHideMenu()
	return muo
}

// SetHideBreadcrumb sets the "hide_breadcrumb" field.
func (muo *MenuUpdateOne) SetHideBreadcrumb(b bool) *MenuUpdateOne {
	muo.mutation.SetHideBreadcrumb(b)
	return muo
}

// SetNillableHideBreadcrumb sets the "hide_breadcrumb" field if the given value is not nil.
func (muo *MenuUpdateOne) SetNillableHideBreadcrumb(b *bool) *MenuUpdateOne {
	if b != nil {
		muo.SetHideBreadcrumb(*b)
	}
	return muo
}

// ClearHideBreadcrumb clears the value of the "hide_breadcrumb" field.
func (muo *MenuUpdateOne) ClearHideBreadcrumb() *MenuUpdateOne {
	muo.mutation.ClearHideBreadcrumb()
	return muo
}

// SetCurrentActiveMenu sets the "current_active_menu" field.
func (muo *MenuUpdateOne) SetCurrentActiveMenu(s string) *MenuUpdateOne {
	muo.mutation.SetCurrentActiveMenu(s)
	return muo
}

// SetNillableCurrentActiveMenu sets the "current_active_menu" field if the given value is not nil.
func (muo *MenuUpdateOne) SetNillableCurrentActiveMenu(s *string) *MenuUpdateOne {
	if s != nil {
		muo.SetCurrentActiveMenu(*s)
	}
	return muo
}

// ClearCurrentActiveMenu clears the value of the "current_active_menu" field.
func (muo *MenuUpdateOne) ClearCurrentActiveMenu() *MenuUpdateOne {
	muo.mutation.ClearCurrentActiveMenu()
	return muo
}

// SetIgnoreKeepAlive sets the "ignore_keep_alive" field.
func (muo *MenuUpdateOne) SetIgnoreKeepAlive(b bool) *MenuUpdateOne {
	muo.mutation.SetIgnoreKeepAlive(b)
	return muo
}

// SetNillableIgnoreKeepAlive sets the "ignore_keep_alive" field if the given value is not nil.
func (muo *MenuUpdateOne) SetNillableIgnoreKeepAlive(b *bool) *MenuUpdateOne {
	if b != nil {
		muo.SetIgnoreKeepAlive(*b)
	}
	return muo
}

// ClearIgnoreKeepAlive clears the value of the "ignore_keep_alive" field.
func (muo *MenuUpdateOne) ClearIgnoreKeepAlive() *MenuUpdateOne {
	muo.mutation.ClearIgnoreKeepAlive()
	return muo
}

// SetHideTab sets the "hide_tab" field.
func (muo *MenuUpdateOne) SetHideTab(b bool) *MenuUpdateOne {
	muo.mutation.SetHideTab(b)
	return muo
}

// SetNillableHideTab sets the "hide_tab" field if the given value is not nil.
func (muo *MenuUpdateOne) SetNillableHideTab(b *bool) *MenuUpdateOne {
	if b != nil {
		muo.SetHideTab(*b)
	}
	return muo
}

// ClearHideTab clears the value of the "hide_tab" field.
func (muo *MenuUpdateOne) ClearHideTab() *MenuUpdateOne {
	muo.mutation.ClearHideTab()
	return muo
}

// SetFrameSrc sets the "frame_src" field.
func (muo *MenuUpdateOne) SetFrameSrc(s string) *MenuUpdateOne {
	muo.mutation.SetFrameSrc(s)
	return muo
}

// SetNillableFrameSrc sets the "frame_src" field if the given value is not nil.
func (muo *MenuUpdateOne) SetNillableFrameSrc(s *string) *MenuUpdateOne {
	if s != nil {
		muo.SetFrameSrc(*s)
	}
	return muo
}

// ClearFrameSrc clears the value of the "frame_src" field.
func (muo *MenuUpdateOne) ClearFrameSrc() *MenuUpdateOne {
	muo.mutation.ClearFrameSrc()
	return muo
}

// SetCarryParam sets the "carry_param" field.
func (muo *MenuUpdateOne) SetCarryParam(b bool) *MenuUpdateOne {
	muo.mutation.SetCarryParam(b)
	return muo
}

// SetNillableCarryParam sets the "carry_param" field if the given value is not nil.
func (muo *MenuUpdateOne) SetNillableCarryParam(b *bool) *MenuUpdateOne {
	if b != nil {
		muo.SetCarryParam(*b)
	}
	return muo
}

// ClearCarryParam clears the value of the "carry_param" field.
func (muo *MenuUpdateOne) ClearCarryParam() *MenuUpdateOne {
	muo.mutation.ClearCarryParam()
	return muo
}

// SetHideChildrenInMenu sets the "hide_children_in_menu" field.
func (muo *MenuUpdateOne) SetHideChildrenInMenu(b bool) *MenuUpdateOne {
	muo.mutation.SetHideChildrenInMenu(b)
	return muo
}

// SetNillableHideChildrenInMenu sets the "hide_children_in_menu" field if the given value is not nil.
func (muo *MenuUpdateOne) SetNillableHideChildrenInMenu(b *bool) *MenuUpdateOne {
	if b != nil {
		muo.SetHideChildrenInMenu(*b)
	}
	return muo
}

// ClearHideChildrenInMenu clears the value of the "hide_children_in_menu" field.
func (muo *MenuUpdateOne) ClearHideChildrenInMenu() *MenuUpdateOne {
	muo.mutation.ClearHideChildrenInMenu()
	return muo
}

// SetAffix sets the "affix" field.
func (muo *MenuUpdateOne) SetAffix(b bool) *MenuUpdateOne {
	muo.mutation.SetAffix(b)
	return muo
}

// SetNillableAffix sets the "affix" field if the given value is not nil.
func (muo *MenuUpdateOne) SetNillableAffix(b *bool) *MenuUpdateOne {
	if b != nil {
		muo.SetAffix(*b)
	}
	return muo
}

// ClearAffix clears the value of the "affix" field.
func (muo *MenuUpdateOne) ClearAffix() *MenuUpdateOne {
	muo.mutation.ClearAffix()
	return muo
}

// SetDynamicLevel sets the "dynamic_level" field.
func (muo *MenuUpdateOne) SetDynamicLevel(u uint32) *MenuUpdateOne {
	muo.mutation.ResetDynamicLevel()
	muo.mutation.SetDynamicLevel(u)
	return muo
}

// SetNillableDynamicLevel sets the "dynamic_level" field if the given value is not nil.
func (muo *MenuUpdateOne) SetNillableDynamicLevel(u *uint32) *MenuUpdateOne {
	if u != nil {
		muo.SetDynamicLevel(*u)
	}
	return muo
}

// AddDynamicLevel adds u to the "dynamic_level" field.
func (muo *MenuUpdateOne) AddDynamicLevel(u int32) *MenuUpdateOne {
	muo.mutation.AddDynamicLevel(u)
	return muo
}

// ClearDynamicLevel clears the value of the "dynamic_level" field.
func (muo *MenuUpdateOne) ClearDynamicLevel() *MenuUpdateOne {
	muo.mutation.ClearDynamicLevel()
	return muo
}

// SetRealPath sets the "real_path" field.
func (muo *MenuUpdateOne) SetRealPath(s string) *MenuUpdateOne {
	muo.mutation.SetRealPath(s)
	return muo
}

// SetNillableRealPath sets the "real_path" field if the given value is not nil.
func (muo *MenuUpdateOne) SetNillableRealPath(s *string) *MenuUpdateOne {
	if s != nil {
		muo.SetRealPath(*s)
	}
	return muo
}

// ClearRealPath clears the value of the "real_path" field.
func (muo *MenuUpdateOne) ClearRealPath() *MenuUpdateOne {
	muo.mutation.ClearRealPath()
	return muo
}

// AddRoleIDs adds the "roles" edge to the Role entity by IDs.
func (muo *MenuUpdateOne) AddRoleIDs(ids ...uint64) *MenuUpdateOne {
	muo.mutation.AddRoleIDs(ids...)
	return muo
}

// AddRoles adds the "roles" edges to the Role entity.
func (muo *MenuUpdateOne) AddRoles(r ...*Role) *MenuUpdateOne {
	ids := make([]uint64, len(r))
	for i := range r {
		ids[i] = r[i].ID
	}
	return muo.AddRoleIDs(ids...)
}

// SetParent sets the "parent" edge to the Menu entity.
func (muo *MenuUpdateOne) SetParent(m *Menu) *MenuUpdateOne {
	return muo.SetParentID(m.ID)
}

// AddChildIDs adds the "children" edge to the Menu entity by IDs.
func (muo *MenuUpdateOne) AddChildIDs(ids ...uint64) *MenuUpdateOne {
	muo.mutation.AddChildIDs(ids...)
	return muo
}

// AddChildren adds the "children" edges to the Menu entity.
func (muo *MenuUpdateOne) AddChildren(m ...*Menu) *MenuUpdateOne {
	ids := make([]uint64, len(m))
	for i := range m {
		ids[i] = m[i].ID
	}
	return muo.AddChildIDs(ids...)
}

// AddParamIDs adds the "params" edge to the MenuParam entity by IDs.
func (muo *MenuUpdateOne) AddParamIDs(ids ...uint64) *MenuUpdateOne {
	muo.mutation.AddParamIDs(ids...)
	return muo
}

// AddParams adds the "params" edges to the MenuParam entity.
func (muo *MenuUpdateOne) AddParams(m ...*MenuParam) *MenuUpdateOne {
	ids := make([]uint64, len(m))
	for i := range m {
		ids[i] = m[i].ID
	}
	return muo.AddParamIDs(ids...)
}

// Mutation returns the MenuMutation object of the builder.
func (muo *MenuUpdateOne) Mutation() *MenuMutation {
	return muo.mutation
}

// ClearRoles clears all "roles" edges to the Role entity.
func (muo *MenuUpdateOne) ClearRoles() *MenuUpdateOne {
	muo.mutation.ClearRoles()
	return muo
}

// RemoveRoleIDs removes the "roles" edge to Role entities by IDs.
func (muo *MenuUpdateOne) RemoveRoleIDs(ids ...uint64) *MenuUpdateOne {
	muo.mutation.RemoveRoleIDs(ids...)
	return muo
}

// RemoveRoles removes "roles" edges to Role entities.
func (muo *MenuUpdateOne) RemoveRoles(r ...*Role) *MenuUpdateOne {
	ids := make([]uint64, len(r))
	for i := range r {
		ids[i] = r[i].ID
	}
	return muo.RemoveRoleIDs(ids...)
}

// ClearParent clears the "parent" edge to the Menu entity.
func (muo *MenuUpdateOne) ClearParent() *MenuUpdateOne {
	muo.mutation.ClearParent()
	return muo
}

// ClearChildren clears all "children" edges to the Menu entity.
func (muo *MenuUpdateOne) ClearChildren() *MenuUpdateOne {
	muo.mutation.ClearChildren()
	return muo
}

// RemoveChildIDs removes the "children" edge to Menu entities by IDs.
func (muo *MenuUpdateOne) RemoveChildIDs(ids ...uint64) *MenuUpdateOne {
	muo.mutation.RemoveChildIDs(ids...)
	return muo
}

// RemoveChildren removes "children" edges to Menu entities.
func (muo *MenuUpdateOne) RemoveChildren(m ...*Menu) *MenuUpdateOne {
	ids := make([]uint64, len(m))
	for i := range m {
		ids[i] = m[i].ID
	}
	return muo.RemoveChildIDs(ids...)
}

// ClearParams clears all "params" edges to the MenuParam entity.
func (muo *MenuUpdateOne) ClearParams() *MenuUpdateOne {
	muo.mutation.ClearParams()
	return muo
}

// RemoveParamIDs removes the "params" edge to MenuParam entities by IDs.
func (muo *MenuUpdateOne) RemoveParamIDs(ids ...uint64) *MenuUpdateOne {
	muo.mutation.RemoveParamIDs(ids...)
	return muo
}

// RemoveParams removes "params" edges to MenuParam entities.
func (muo *MenuUpdateOne) RemoveParams(m ...*MenuParam) *MenuUpdateOne {
	ids := make([]uint64, len(m))
	for i := range m {
		ids[i] = m[i].ID
	}
	return muo.RemoveParamIDs(ids...)
}

// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (muo *MenuUpdateOne) Select(field string, fields ...string) *MenuUpdateOne {
	muo.fields = append([]string{field}, fields...)
	return muo
}

// Save executes the query and returns the updated Menu entity.
func (muo *MenuUpdateOne) Save(ctx context.Context) (*Menu, error) {
	muo.defaults()
	return withHooks[*Menu, MenuMutation](ctx, muo.sqlSave, muo.mutation, muo.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (muo *MenuUpdateOne) SaveX(ctx context.Context) *Menu {
	node, err := muo.Save(ctx)
	if err != nil {
		panic(err)
	}
	return node
}

// Exec executes the query on the entity.
func (muo *MenuUpdateOne) Exec(ctx context.Context) error {
	_, err := muo.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (muo *MenuUpdateOne) ExecX(ctx context.Context) {
	if err := muo.Exec(ctx); err != nil {
		panic(err)
	}
}

// defaults sets the default values of the builder before save.
func (muo *MenuUpdateOne) defaults() {
	if _, ok := muo.mutation.UpdatedAt(); !ok {
		v := menu.UpdateDefaultUpdatedAt()
		muo.mutation.SetUpdatedAt(v)
	}
}

func (muo *MenuUpdateOne) sqlSave(ctx context.Context) (_node *Menu, err error) {
	_spec := &sqlgraph.UpdateSpec{
		Node: &sqlgraph.NodeSpec{
			Table:   menu.Table,
			Columns: menu.Columns,
			ID: &sqlgraph.FieldSpec{
				Type:   field.TypeUint64,
				Column: menu.FieldID,
			},
		},
	}
	id, ok := muo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Menu.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := muo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, menu.FieldID)
		for _, f := range fields {
			if !menu.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != menu.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := muo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := muo.mutation.UpdatedAt(); ok {
		_spec.SetField(menu.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := muo.mutation.MenuLevel(); ok {
		_spec.SetField(menu.FieldMenuLevel, field.TypeUint32, value)
	}
	if value, ok := muo.mutation.AddedMenuLevel(); ok {
		_spec.AddField(menu.FieldMenuLevel, field.TypeUint32, value)
	}
	if value, ok := muo.mutation.MenuType(); ok {
		_spec.SetField(menu.FieldMenuType, field.TypeUint32, value)
	}
	if value, ok := muo.mutation.AddedMenuType(); ok {
		_spec.AddField(menu.FieldMenuType, field.TypeUint32, value)
	}
	if value, ok := muo.mutation.Path(); ok {
		_spec.SetField(menu.FieldPath, field.TypeString, value)
	}
	if muo.mutation.PathCleared() {
		_spec.ClearField(menu.FieldPath, field.TypeString)
	}
	if value, ok := muo.mutation.Name(); ok {
		_spec.SetField(menu.FieldName, field.TypeString, value)
	}
	if value, ok := muo.mutation.Redirect(); ok {
		_spec.SetField(menu.FieldRedirect, field.TypeString, value)
	}
	if muo.mutation.RedirectCleared() {
		_spec.ClearField(menu.FieldRedirect, field.TypeString)
	}
	if value, ok := muo.mutation.Component(); ok {
		_spec.SetField(menu.FieldComponent, field.TypeString, value)
	}
	if muo.mutation.ComponentCleared() {
		_spec.ClearField(menu.FieldComponent, field.TypeString)
	}
	if value, ok := muo.mutation.OrderNo(); ok {
		_spec.SetField(menu.FieldOrderNo, field.TypeUint32, value)
	}
	if value, ok := muo.mutation.AddedOrderNo(); ok {
		_spec.AddField(menu.FieldOrderNo, field.TypeUint32, value)
	}
	if value, ok := muo.mutation.Disabled(); ok {
		_spec.SetField(menu.FieldDisabled, field.TypeBool, value)
	}
	if muo.mutation.DisabledCleared() {
		_spec.ClearField(menu.FieldDisabled, field.TypeBool)
	}
	if value, ok := muo.mutation.Title(); ok {
		_spec.SetField(menu.FieldTitle, field.TypeString, value)
	}
	if value, ok := muo.mutation.Icon(); ok {
		_spec.SetField(menu.FieldIcon, field.TypeString, value)
	}
	if value, ok := muo.mutation.HideMenu(); ok {
		_spec.SetField(menu.FieldHideMenu, field.TypeBool, value)
	}
	if muo.mutation.HideMenuCleared() {
		_spec.ClearField(menu.FieldHideMenu, field.TypeBool)
	}
	if value, ok := muo.mutation.HideBreadcrumb(); ok {
		_spec.SetField(menu.FieldHideBreadcrumb, field.TypeBool, value)
	}
	if muo.mutation.HideBreadcrumbCleared() {
		_spec.ClearField(menu.FieldHideBreadcrumb, field.TypeBool)
	}
	if value, ok := muo.mutation.CurrentActiveMenu(); ok {
		_spec.SetField(menu.FieldCurrentActiveMenu, field.TypeString, value)
	}
	if muo.mutation.CurrentActiveMenuCleared() {
		_spec.ClearField(menu.FieldCurrentActiveMenu, field.TypeString)
	}
	if value, ok := muo.mutation.IgnoreKeepAlive(); ok {
		_spec.SetField(menu.FieldIgnoreKeepAlive, field.TypeBool, value)
	}
	if muo.mutation.IgnoreKeepAliveCleared() {
		_spec.ClearField(menu.FieldIgnoreKeepAlive, field.TypeBool)
	}
	if value, ok := muo.mutation.HideTab(); ok {
		_spec.SetField(menu.FieldHideTab, field.TypeBool, value)
	}
	if muo.mutation.HideTabCleared() {
		_spec.ClearField(menu.FieldHideTab, field.TypeBool)
	}
	if value, ok := muo.mutation.FrameSrc(); ok {
		_spec.SetField(menu.FieldFrameSrc, field.TypeString, value)
	}
	if muo.mutation.FrameSrcCleared() {
		_spec.ClearField(menu.FieldFrameSrc, field.TypeString)
	}
	if value, ok := muo.mutation.CarryParam(); ok {
		_spec.SetField(menu.FieldCarryParam, field.TypeBool, value)
	}
	if muo.mutation.CarryParamCleared() {
		_spec.ClearField(menu.FieldCarryParam, field.TypeBool)
	}
	if value, ok := muo.mutation.HideChildrenInMenu(); ok {
		_spec.SetField(menu.FieldHideChildrenInMenu, field.TypeBool, value)
	}
	if muo.mutation.HideChildrenInMenuCleared() {
		_spec.ClearField(menu.FieldHideChildrenInMenu, field.TypeBool)
	}
	if value, ok := muo.mutation.Affix(); ok {
		_spec.SetField(menu.FieldAffix, field.TypeBool, value)
	}
	if muo.mutation.AffixCleared() {
		_spec.ClearField(menu.FieldAffix, field.TypeBool)
	}
	if value, ok := muo.mutation.DynamicLevel(); ok {
		_spec.SetField(menu.FieldDynamicLevel, field.TypeUint32, value)
	}
	if value, ok := muo.mutation.AddedDynamicLevel(); ok {
		_spec.AddField(menu.FieldDynamicLevel, field.TypeUint32, value)
	}
	if muo.mutation.DynamicLevelCleared() {
		_spec.ClearField(menu.FieldDynamicLevel, field.TypeUint32)
	}
	if value, ok := muo.mutation.RealPath(); ok {
		_spec.SetField(menu.FieldRealPath, field.TypeString, value)
	}
	if muo.mutation.RealPathCleared() {
		_spec.ClearField(menu.FieldRealPath, field.TypeString)
	}
	if muo.mutation.RolesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   menu.RolesTable,
			Columns: menu.RolesPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUint64,
					Column: role.FieldID,
				},
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := muo.mutation.RemovedRolesIDs(); len(nodes) > 0 && !muo.mutation.RolesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   menu.RolesTable,
			Columns: menu.RolesPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUint64,
					Column: role.FieldID,
				},
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := muo.mutation.RolesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   menu.RolesTable,
			Columns: menu.RolesPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUint64,
					Column: role.FieldID,
				},
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if muo.mutation.ParentCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   menu.ParentTable,
			Columns: []string{menu.ParentColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUint64,
					Column: menu.FieldID,
				},
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := muo.mutation.ParentIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   menu.ParentTable,
			Columns: []string{menu.ParentColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUint64,
					Column: menu.FieldID,
				},
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if muo.mutation.ChildrenCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   menu.ChildrenTable,
			Columns: []string{menu.ChildrenColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUint64,
					Column: menu.FieldID,
				},
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := muo.mutation.RemovedChildrenIDs(); len(nodes) > 0 && !muo.mutation.ChildrenCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   menu.ChildrenTable,
			Columns: []string{menu.ChildrenColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUint64,
					Column: menu.FieldID,
				},
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := muo.mutation.ChildrenIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   menu.ChildrenTable,
			Columns: []string{menu.ChildrenColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUint64,
					Column: menu.FieldID,
				},
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if muo.mutation.ParamsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   menu.ParamsTable,
			Columns: []string{menu.ParamsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUint64,
					Column: menuparam.FieldID,
				},
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := muo.mutation.RemovedParamsIDs(); len(nodes) > 0 && !muo.mutation.ParamsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   menu.ParamsTable,
			Columns: []string{menu.ParamsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUint64,
					Column: menuparam.FieldID,
				},
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := muo.mutation.ParamsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   menu.ParamsTable,
			Columns: []string{menu.ParamsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUint64,
					Column: menuparam.FieldID,
				},
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &Menu{config: muo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, muo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{menu.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	muo.mutation.done = true
	return _node, nil
}
