// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"time"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"github.com/anzhiyu-c/anheyu-app/ent/directlink"
	"github.com/anzhiyu-c/anheyu-app/ent/entity"
	"github.com/anzhiyu-c/anheyu-app/ent/file"
	"github.com/anzhiyu-c/anheyu-app/ent/fileentity"
	"github.com/anzhiyu-c/anheyu-app/ent/metadata"
	"github.com/anzhiyu-c/anheyu-app/ent/predicate"
	"github.com/anzhiyu-c/anheyu-app/ent/user"
)

// FileUpdate is the builder for updating File entities.
type FileUpdate struct {
	config
	hooks     []Hook
	mutation  *FileMutation
	modifiers []func(*sql.UpdateBuilder)
}

// Where appends a list predicates to the FileUpdate builder.
func (_u *FileUpdate) Where(ps ...predicate.File) *FileUpdate {
	_u.mutation.Where(ps...)
	return _u
}

// SetDeletedAt sets the "deleted_at" field.
func (_u *FileUpdate) SetDeletedAt(v time.Time) *FileUpdate {
	_u.mutation.SetDeletedAt(v)
	return _u
}

// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (_u *FileUpdate) SetNillableDeletedAt(v *time.Time) *FileUpdate {
	if v != nil {
		_u.SetDeletedAt(*v)
	}
	return _u
}

// ClearDeletedAt clears the value of the "deleted_at" field.
func (_u *FileUpdate) ClearDeletedAt() *FileUpdate {
	_u.mutation.ClearDeletedAt()
	return _u
}

// SetUpdatedAt sets the "updated_at" field.
func (_u *FileUpdate) SetUpdatedAt(v time.Time) *FileUpdate {
	_u.mutation.SetUpdatedAt(v)
	return _u
}

// SetType sets the "type" field.
func (_u *FileUpdate) SetType(v int) *FileUpdate {
	_u.mutation.ResetType()
	_u.mutation.SetType(v)
	return _u
}

// SetNillableType sets the "type" field if the given value is not nil.
func (_u *FileUpdate) SetNillableType(v *int) *FileUpdate {
	if v != nil {
		_u.SetType(*v)
	}
	return _u
}

// AddType adds value to the "type" field.
func (_u *FileUpdate) AddType(v int) *FileUpdate {
	_u.mutation.AddType(v)
	return _u
}

// SetOwnerID sets the "owner_id" field.
func (_u *FileUpdate) SetOwnerID(v uint) *FileUpdate {
	_u.mutation.SetOwnerID(v)
	return _u
}

// SetNillableOwnerID sets the "owner_id" field if the given value is not nil.
func (_u *FileUpdate) SetNillableOwnerID(v *uint) *FileUpdate {
	if v != nil {
		_u.SetOwnerID(*v)
	}
	return _u
}

// SetParentID sets the "parent_id" field.
func (_u *FileUpdate) SetParentID(v uint) *FileUpdate {
	_u.mutation.SetParentID(v)
	return _u
}

// SetNillableParentID sets the "parent_id" field if the given value is not nil.
func (_u *FileUpdate) SetNillableParentID(v *uint) *FileUpdate {
	if v != nil {
		_u.SetParentID(*v)
	}
	return _u
}

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

// SetName sets the "name" field.
func (_u *FileUpdate) SetName(v string) *FileUpdate {
	_u.mutation.SetName(v)
	return _u
}

// SetNillableName sets the "name" field if the given value is not nil.
func (_u *FileUpdate) SetNillableName(v *string) *FileUpdate {
	if v != nil {
		_u.SetName(*v)
	}
	return _u
}

// SetSize sets the "size" field.
func (_u *FileUpdate) SetSize(v int64) *FileUpdate {
	_u.mutation.ResetSize()
	_u.mutation.SetSize(v)
	return _u
}

// SetNillableSize sets the "size" field if the given value is not nil.
func (_u *FileUpdate) SetNillableSize(v *int64) *FileUpdate {
	if v != nil {
		_u.SetSize(*v)
	}
	return _u
}

// AddSize adds value to the "size" field.
func (_u *FileUpdate) AddSize(v int64) *FileUpdate {
	_u.mutation.AddSize(v)
	return _u
}

// SetPrimaryEntityID sets the "primary_entity_id" field.
func (_u *FileUpdate) SetPrimaryEntityID(v uint) *FileUpdate {
	_u.mutation.SetPrimaryEntityID(v)
	return _u
}

// SetNillablePrimaryEntityID sets the "primary_entity_id" field if the given value is not nil.
func (_u *FileUpdate) SetNillablePrimaryEntityID(v *uint) *FileUpdate {
	if v != nil {
		_u.SetPrimaryEntityID(*v)
	}
	return _u
}

// ClearPrimaryEntityID clears the value of the "primary_entity_id" field.
func (_u *FileUpdate) ClearPrimaryEntityID() *FileUpdate {
	_u.mutation.ClearPrimaryEntityID()
	return _u
}

// SetChildrenCount sets the "children_count" field.
func (_u *FileUpdate) SetChildrenCount(v int64) *FileUpdate {
	_u.mutation.ResetChildrenCount()
	_u.mutation.SetChildrenCount(v)
	return _u
}

// SetNillableChildrenCount sets the "children_count" field if the given value is not nil.
func (_u *FileUpdate) SetNillableChildrenCount(v *int64) *FileUpdate {
	if v != nil {
		_u.SetChildrenCount(*v)
	}
	return _u
}

// AddChildrenCount adds value to the "children_count" field.
func (_u *FileUpdate) AddChildrenCount(v int64) *FileUpdate {
	_u.mutation.AddChildrenCount(v)
	return _u
}

// SetViewConfig sets the "view_config" field.
func (_u *FileUpdate) SetViewConfig(v string) *FileUpdate {
	_u.mutation.SetViewConfig(v)
	return _u
}

// SetNillableViewConfig sets the "view_config" field if the given value is not nil.
func (_u *FileUpdate) SetNillableViewConfig(v *string) *FileUpdate {
	if v != nil {
		_u.SetViewConfig(*v)
	}
	return _u
}

// ClearViewConfig clears the value of the "view_config" field.
func (_u *FileUpdate) ClearViewConfig() *FileUpdate {
	_u.mutation.ClearViewConfig()
	return _u
}

// SetOwner sets the "owner" edge to the User entity.
func (_u *FileUpdate) SetOwner(v *User) *FileUpdate {
	return _u.SetOwnerID(v.ID)
}

// SetParent sets the "parent" edge to the File entity.
func (_u *FileUpdate) SetParent(v *File) *FileUpdate {
	return _u.SetParentID(v.ID)
}

// AddChildIDs adds the "children" edge to the File entity by IDs.
func (_u *FileUpdate) AddChildIDs(ids ...uint) *FileUpdate {
	_u.mutation.AddChildIDs(ids...)
	return _u
}

// AddChildren adds the "children" edges to the File entity.
func (_u *FileUpdate) AddChildren(v ...*File) *FileUpdate {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddChildIDs(ids...)
}

// SetPrimaryEntity sets the "primary_entity" edge to the Entity entity.
func (_u *FileUpdate) SetPrimaryEntity(v *Entity) *FileUpdate {
	return _u.SetPrimaryEntityID(v.ID)
}

// AddVersionIDs adds the "versions" edge to the FileEntity entity by IDs.
func (_u *FileUpdate) AddVersionIDs(ids ...uint) *FileUpdate {
	_u.mutation.AddVersionIDs(ids...)
	return _u
}

// AddVersions adds the "versions" edges to the FileEntity entity.
func (_u *FileUpdate) AddVersions(v ...*FileEntity) *FileUpdate {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddVersionIDs(ids...)
}

// SetDirectLinkID sets the "direct_link" edge to the DirectLink entity by ID.
func (_u *FileUpdate) SetDirectLinkID(id uint) *FileUpdate {
	_u.mutation.SetDirectLinkID(id)
	return _u
}

// SetNillableDirectLinkID sets the "direct_link" edge to the DirectLink entity by ID if the given value is not nil.
func (_u *FileUpdate) SetNillableDirectLinkID(id *uint) *FileUpdate {
	if id != nil {
		_u = _u.SetDirectLinkID(*id)
	}
	return _u
}

// SetDirectLink sets the "direct_link" edge to the DirectLink entity.
func (_u *FileUpdate) SetDirectLink(v *DirectLink) *FileUpdate {
	return _u.SetDirectLinkID(v.ID)
}

// AddMetadatumIDs adds the "metadata" edge to the Metadata entity by IDs.
func (_u *FileUpdate) AddMetadatumIDs(ids ...uint) *FileUpdate {
	_u.mutation.AddMetadatumIDs(ids...)
	return _u
}

// AddMetadata adds the "metadata" edges to the Metadata entity.
func (_u *FileUpdate) AddMetadata(v ...*Metadata) *FileUpdate {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddMetadatumIDs(ids...)
}

// Mutation returns the FileMutation object of the builder.
func (_u *FileUpdate) Mutation() *FileMutation {
	return _u.mutation
}

// ClearOwner clears the "owner" edge to the User entity.
func (_u *FileUpdate) ClearOwner() *FileUpdate {
	_u.mutation.ClearOwner()
	return _u
}

// ClearParent clears the "parent" edge to the File entity.
func (_u *FileUpdate) ClearParent() *FileUpdate {
	_u.mutation.ClearParent()
	return _u
}

// ClearChildren clears all "children" edges to the File entity.
func (_u *FileUpdate) ClearChildren() *FileUpdate {
	_u.mutation.ClearChildren()
	return _u
}

// RemoveChildIDs removes the "children" edge to File entities by IDs.
func (_u *FileUpdate) RemoveChildIDs(ids ...uint) *FileUpdate {
	_u.mutation.RemoveChildIDs(ids...)
	return _u
}

// RemoveChildren removes "children" edges to File entities.
func (_u *FileUpdate) RemoveChildren(v ...*File) *FileUpdate {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveChildIDs(ids...)
}

// ClearPrimaryEntity clears the "primary_entity" edge to the Entity entity.
func (_u *FileUpdate) ClearPrimaryEntity() *FileUpdate {
	_u.mutation.ClearPrimaryEntity()
	return _u
}

// ClearVersions clears all "versions" edges to the FileEntity entity.
func (_u *FileUpdate) ClearVersions() *FileUpdate {
	_u.mutation.ClearVersions()
	return _u
}

// RemoveVersionIDs removes the "versions" edge to FileEntity entities by IDs.
func (_u *FileUpdate) RemoveVersionIDs(ids ...uint) *FileUpdate {
	_u.mutation.RemoveVersionIDs(ids...)
	return _u
}

// RemoveVersions removes "versions" edges to FileEntity entities.
func (_u *FileUpdate) RemoveVersions(v ...*FileEntity) *FileUpdate {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveVersionIDs(ids...)
}

// ClearDirectLink clears the "direct_link" edge to the DirectLink entity.
func (_u *FileUpdate) ClearDirectLink() *FileUpdate {
	_u.mutation.ClearDirectLink()
	return _u
}

// ClearMetadata clears all "metadata" edges to the Metadata entity.
func (_u *FileUpdate) ClearMetadata() *FileUpdate {
	_u.mutation.ClearMetadata()
	return _u
}

// RemoveMetadatumIDs removes the "metadata" edge to Metadata entities by IDs.
func (_u *FileUpdate) RemoveMetadatumIDs(ids ...uint) *FileUpdate {
	_u.mutation.RemoveMetadatumIDs(ids...)
	return _u
}

// RemoveMetadata removes "metadata" edges to Metadata entities.
func (_u *FileUpdate) RemoveMetadata(v ...*Metadata) *FileUpdate {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveMetadatumIDs(ids...)
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *FileUpdate) Save(ctx context.Context) (int, error) {
	if err := _u.defaults(); err != nil {
		return 0, err
	}
	return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}

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

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

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

// defaults sets the default values of the builder before save.
func (_u *FileUpdate) defaults() error {
	if _, ok := _u.mutation.UpdatedAt(); !ok {
		if file.UpdateDefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized file.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := file.UpdateDefaultUpdatedAt()
		_u.mutation.SetUpdatedAt(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (_u *FileUpdate) check() error {
	if v, ok := _u.mutation.Name(); ok {
		if err := file.NameValidator(v); err != nil {
			return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "File.name": %w`, err)}
		}
	}
	if _u.mutation.OwnerCleared() && len(_u.mutation.OwnerIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "File.owner"`)
	}
	return nil
}

// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *FileUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *FileUpdate {
	_u.modifiers = append(_u.modifiers, modifiers...)
	return _u
}

func (_u *FileUpdate) sqlSave(ctx context.Context) (_node int, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(file.Table, file.Columns, sqlgraph.NewFieldSpec(file.FieldID, field.TypeUint))
	if ps := _u.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := _u.mutation.DeletedAt(); ok {
		_spec.SetField(file.FieldDeletedAt, field.TypeTime, value)
	}
	if _u.mutation.DeletedAtCleared() {
		_spec.ClearField(file.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(file.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.GetType(); ok {
		_spec.SetField(file.FieldType, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedType(); ok {
		_spec.AddField(file.FieldType, field.TypeInt, value)
	}
	if value, ok := _u.mutation.Name(); ok {
		_spec.SetField(file.FieldName, field.TypeString, value)
	}
	if value, ok := _u.mutation.Size(); ok {
		_spec.SetField(file.FieldSize, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedSize(); ok {
		_spec.AddField(file.FieldSize, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.ChildrenCount(); ok {
		_spec.SetField(file.FieldChildrenCount, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedChildrenCount(); ok {
		_spec.AddField(file.FieldChildrenCount, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.ViewConfig(); ok {
		_spec.SetField(file.FieldViewConfig, field.TypeString, value)
	}
	if _u.mutation.ViewConfigCleared() {
		_spec.ClearField(file.FieldViewConfig, field.TypeString)
	}
	if _u.mutation.OwnerCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   file.OwnerTable,
			Columns: []string{file.OwnerColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.OwnerIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   file.OwnerTable,
			Columns: []string{file.OwnerColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.ParentCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   file.ParentTable,
			Columns: []string{file.ParentColumn},
			Bidi:    true,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.ParentIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   file.ParentTable,
			Columns: []string{file.ParentColumn},
			Bidi:    true,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.ChildrenCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: true,
			Table:   file.ChildrenTable,
			Columns: []string{file.ChildrenColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedChildrenIDs(); len(nodes) > 0 && !_u.mutation.ChildrenCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: true,
			Table:   file.ChildrenTable,
			Columns: []string{file.ChildrenColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.ChildrenIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: true,
			Table:   file.ChildrenTable,
			Columns: []string{file.ChildrenColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.PrimaryEntityCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   file.PrimaryEntityTable,
			Columns: []string{file.PrimaryEntityColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.PrimaryEntityIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   file.PrimaryEntityTable,
			Columns: []string{file.PrimaryEntityColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.VersionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.VersionsTable,
			Columns: []string{file.VersionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(fileentity.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedVersionsIDs(); len(nodes) > 0 && !_u.mutation.VersionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.VersionsTable,
			Columns: []string{file.VersionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(fileentity.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.VersionsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.VersionsTable,
			Columns: []string{file.VersionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(fileentity.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.DirectLinkCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   file.DirectLinkTable,
			Columns: []string{file.DirectLinkColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(directlink.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.DirectLinkIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   file.DirectLinkTable,
			Columns: []string{file.DirectLinkColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(directlink.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.MetadataCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.MetadataTable,
			Columns: []string{file.MetadataColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(metadata.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedMetadataIDs(); len(nodes) > 0 && !_u.mutation.MetadataCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.MetadataTable,
			Columns: []string{file.MetadataColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(metadata.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.MetadataIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.MetadataTable,
			Columns: []string{file.MetadataColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(metadata.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_spec.AddModifiers(_u.modifiers...)
	if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{file.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	_u.mutation.done = true
	return _node, nil
}

// FileUpdateOne is the builder for updating a single File entity.
type FileUpdateOne struct {
	config
	fields    []string
	hooks     []Hook
	mutation  *FileMutation
	modifiers []func(*sql.UpdateBuilder)
}

// SetDeletedAt sets the "deleted_at" field.
func (_u *FileUpdateOne) SetDeletedAt(v time.Time) *FileUpdateOne {
	_u.mutation.SetDeletedAt(v)
	return _u
}

// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (_u *FileUpdateOne) SetNillableDeletedAt(v *time.Time) *FileUpdateOne {
	if v != nil {
		_u.SetDeletedAt(*v)
	}
	return _u
}

// ClearDeletedAt clears the value of the "deleted_at" field.
func (_u *FileUpdateOne) ClearDeletedAt() *FileUpdateOne {
	_u.mutation.ClearDeletedAt()
	return _u
}

// SetUpdatedAt sets the "updated_at" field.
func (_u *FileUpdateOne) SetUpdatedAt(v time.Time) *FileUpdateOne {
	_u.mutation.SetUpdatedAt(v)
	return _u
}

// SetType sets the "type" field.
func (_u *FileUpdateOne) SetType(v int) *FileUpdateOne {
	_u.mutation.ResetType()
	_u.mutation.SetType(v)
	return _u
}

// SetNillableType sets the "type" field if the given value is not nil.
func (_u *FileUpdateOne) SetNillableType(v *int) *FileUpdateOne {
	if v != nil {
		_u.SetType(*v)
	}
	return _u
}

// AddType adds value to the "type" field.
func (_u *FileUpdateOne) AddType(v int) *FileUpdateOne {
	_u.mutation.AddType(v)
	return _u
}

// SetOwnerID sets the "owner_id" field.
func (_u *FileUpdateOne) SetOwnerID(v uint) *FileUpdateOne {
	_u.mutation.SetOwnerID(v)
	return _u
}

// SetNillableOwnerID sets the "owner_id" field if the given value is not nil.
func (_u *FileUpdateOne) SetNillableOwnerID(v *uint) *FileUpdateOne {
	if v != nil {
		_u.SetOwnerID(*v)
	}
	return _u
}

// SetParentID sets the "parent_id" field.
func (_u *FileUpdateOne) SetParentID(v uint) *FileUpdateOne {
	_u.mutation.SetParentID(v)
	return _u
}

// SetNillableParentID sets the "parent_id" field if the given value is not nil.
func (_u *FileUpdateOne) SetNillableParentID(v *uint) *FileUpdateOne {
	if v != nil {
		_u.SetParentID(*v)
	}
	return _u
}

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

// SetName sets the "name" field.
func (_u *FileUpdateOne) SetName(v string) *FileUpdateOne {
	_u.mutation.SetName(v)
	return _u
}

// SetNillableName sets the "name" field if the given value is not nil.
func (_u *FileUpdateOne) SetNillableName(v *string) *FileUpdateOne {
	if v != nil {
		_u.SetName(*v)
	}
	return _u
}

// SetSize sets the "size" field.
func (_u *FileUpdateOne) SetSize(v int64) *FileUpdateOne {
	_u.mutation.ResetSize()
	_u.mutation.SetSize(v)
	return _u
}

// SetNillableSize sets the "size" field if the given value is not nil.
func (_u *FileUpdateOne) SetNillableSize(v *int64) *FileUpdateOne {
	if v != nil {
		_u.SetSize(*v)
	}
	return _u
}

// AddSize adds value to the "size" field.
func (_u *FileUpdateOne) AddSize(v int64) *FileUpdateOne {
	_u.mutation.AddSize(v)
	return _u
}

// SetPrimaryEntityID sets the "primary_entity_id" field.
func (_u *FileUpdateOne) SetPrimaryEntityID(v uint) *FileUpdateOne {
	_u.mutation.SetPrimaryEntityID(v)
	return _u
}

// SetNillablePrimaryEntityID sets the "primary_entity_id" field if the given value is not nil.
func (_u *FileUpdateOne) SetNillablePrimaryEntityID(v *uint) *FileUpdateOne {
	if v != nil {
		_u.SetPrimaryEntityID(*v)
	}
	return _u
}

// ClearPrimaryEntityID clears the value of the "primary_entity_id" field.
func (_u *FileUpdateOne) ClearPrimaryEntityID() *FileUpdateOne {
	_u.mutation.ClearPrimaryEntityID()
	return _u
}

// SetChildrenCount sets the "children_count" field.
func (_u *FileUpdateOne) SetChildrenCount(v int64) *FileUpdateOne {
	_u.mutation.ResetChildrenCount()
	_u.mutation.SetChildrenCount(v)
	return _u
}

// SetNillableChildrenCount sets the "children_count" field if the given value is not nil.
func (_u *FileUpdateOne) SetNillableChildrenCount(v *int64) *FileUpdateOne {
	if v != nil {
		_u.SetChildrenCount(*v)
	}
	return _u
}

// AddChildrenCount adds value to the "children_count" field.
func (_u *FileUpdateOne) AddChildrenCount(v int64) *FileUpdateOne {
	_u.mutation.AddChildrenCount(v)
	return _u
}

// SetViewConfig sets the "view_config" field.
func (_u *FileUpdateOne) SetViewConfig(v string) *FileUpdateOne {
	_u.mutation.SetViewConfig(v)
	return _u
}

// SetNillableViewConfig sets the "view_config" field if the given value is not nil.
func (_u *FileUpdateOne) SetNillableViewConfig(v *string) *FileUpdateOne {
	if v != nil {
		_u.SetViewConfig(*v)
	}
	return _u
}

// ClearViewConfig clears the value of the "view_config" field.
func (_u *FileUpdateOne) ClearViewConfig() *FileUpdateOne {
	_u.mutation.ClearViewConfig()
	return _u
}

// SetOwner sets the "owner" edge to the User entity.
func (_u *FileUpdateOne) SetOwner(v *User) *FileUpdateOne {
	return _u.SetOwnerID(v.ID)
}

// SetParent sets the "parent" edge to the File entity.
func (_u *FileUpdateOne) SetParent(v *File) *FileUpdateOne {
	return _u.SetParentID(v.ID)
}

// AddChildIDs adds the "children" edge to the File entity by IDs.
func (_u *FileUpdateOne) AddChildIDs(ids ...uint) *FileUpdateOne {
	_u.mutation.AddChildIDs(ids...)
	return _u
}

// AddChildren adds the "children" edges to the File entity.
func (_u *FileUpdateOne) AddChildren(v ...*File) *FileUpdateOne {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddChildIDs(ids...)
}

// SetPrimaryEntity sets the "primary_entity" edge to the Entity entity.
func (_u *FileUpdateOne) SetPrimaryEntity(v *Entity) *FileUpdateOne {
	return _u.SetPrimaryEntityID(v.ID)
}

// AddVersionIDs adds the "versions" edge to the FileEntity entity by IDs.
func (_u *FileUpdateOne) AddVersionIDs(ids ...uint) *FileUpdateOne {
	_u.mutation.AddVersionIDs(ids...)
	return _u
}

// AddVersions adds the "versions" edges to the FileEntity entity.
func (_u *FileUpdateOne) AddVersions(v ...*FileEntity) *FileUpdateOne {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddVersionIDs(ids...)
}

// SetDirectLinkID sets the "direct_link" edge to the DirectLink entity by ID.
func (_u *FileUpdateOne) SetDirectLinkID(id uint) *FileUpdateOne {
	_u.mutation.SetDirectLinkID(id)
	return _u
}

// SetNillableDirectLinkID sets the "direct_link" edge to the DirectLink entity by ID if the given value is not nil.
func (_u *FileUpdateOne) SetNillableDirectLinkID(id *uint) *FileUpdateOne {
	if id != nil {
		_u = _u.SetDirectLinkID(*id)
	}
	return _u
}

// SetDirectLink sets the "direct_link" edge to the DirectLink entity.
func (_u *FileUpdateOne) SetDirectLink(v *DirectLink) *FileUpdateOne {
	return _u.SetDirectLinkID(v.ID)
}

// AddMetadatumIDs adds the "metadata" edge to the Metadata entity by IDs.
func (_u *FileUpdateOne) AddMetadatumIDs(ids ...uint) *FileUpdateOne {
	_u.mutation.AddMetadatumIDs(ids...)
	return _u
}

// AddMetadata adds the "metadata" edges to the Metadata entity.
func (_u *FileUpdateOne) AddMetadata(v ...*Metadata) *FileUpdateOne {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddMetadatumIDs(ids...)
}

// Mutation returns the FileMutation object of the builder.
func (_u *FileUpdateOne) Mutation() *FileMutation {
	return _u.mutation
}

// ClearOwner clears the "owner" edge to the User entity.
func (_u *FileUpdateOne) ClearOwner() *FileUpdateOne {
	_u.mutation.ClearOwner()
	return _u
}

// ClearParent clears the "parent" edge to the File entity.
func (_u *FileUpdateOne) ClearParent() *FileUpdateOne {
	_u.mutation.ClearParent()
	return _u
}

// ClearChildren clears all "children" edges to the File entity.
func (_u *FileUpdateOne) ClearChildren() *FileUpdateOne {
	_u.mutation.ClearChildren()
	return _u
}

// RemoveChildIDs removes the "children" edge to File entities by IDs.
func (_u *FileUpdateOne) RemoveChildIDs(ids ...uint) *FileUpdateOne {
	_u.mutation.RemoveChildIDs(ids...)
	return _u
}

// RemoveChildren removes "children" edges to File entities.
func (_u *FileUpdateOne) RemoveChildren(v ...*File) *FileUpdateOne {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveChildIDs(ids...)
}

// ClearPrimaryEntity clears the "primary_entity" edge to the Entity entity.
func (_u *FileUpdateOne) ClearPrimaryEntity() *FileUpdateOne {
	_u.mutation.ClearPrimaryEntity()
	return _u
}

// ClearVersions clears all "versions" edges to the FileEntity entity.
func (_u *FileUpdateOne) ClearVersions() *FileUpdateOne {
	_u.mutation.ClearVersions()
	return _u
}

// RemoveVersionIDs removes the "versions" edge to FileEntity entities by IDs.
func (_u *FileUpdateOne) RemoveVersionIDs(ids ...uint) *FileUpdateOne {
	_u.mutation.RemoveVersionIDs(ids...)
	return _u
}

// RemoveVersions removes "versions" edges to FileEntity entities.
func (_u *FileUpdateOne) RemoveVersions(v ...*FileEntity) *FileUpdateOne {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveVersionIDs(ids...)
}

// ClearDirectLink clears the "direct_link" edge to the DirectLink entity.
func (_u *FileUpdateOne) ClearDirectLink() *FileUpdateOne {
	_u.mutation.ClearDirectLink()
	return _u
}

// ClearMetadata clears all "metadata" edges to the Metadata entity.
func (_u *FileUpdateOne) ClearMetadata() *FileUpdateOne {
	_u.mutation.ClearMetadata()
	return _u
}

// RemoveMetadatumIDs removes the "metadata" edge to Metadata entities by IDs.
func (_u *FileUpdateOne) RemoveMetadatumIDs(ids ...uint) *FileUpdateOne {
	_u.mutation.RemoveMetadatumIDs(ids...)
	return _u
}

// RemoveMetadata removes "metadata" edges to Metadata entities.
func (_u *FileUpdateOne) RemoveMetadata(v ...*Metadata) *FileUpdateOne {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveMetadatumIDs(ids...)
}

// Where appends a list predicates to the FileUpdate builder.
func (_u *FileUpdateOne) Where(ps ...predicate.File) *FileUpdateOne {
	_u.mutation.Where(ps...)
	return _u
}

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

// Save executes the query and returns the updated File entity.
func (_u *FileUpdateOne) Save(ctx context.Context) (*File, error) {
	if err := _u.defaults(); err != nil {
		return nil, err
	}
	return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}

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

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

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

// defaults sets the default values of the builder before save.
func (_u *FileUpdateOne) defaults() error {
	if _, ok := _u.mutation.UpdatedAt(); !ok {
		if file.UpdateDefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized file.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := file.UpdateDefaultUpdatedAt()
		_u.mutation.SetUpdatedAt(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (_u *FileUpdateOne) check() error {
	if v, ok := _u.mutation.Name(); ok {
		if err := file.NameValidator(v); err != nil {
			return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "File.name": %w`, err)}
		}
	}
	if _u.mutation.OwnerCleared() && len(_u.mutation.OwnerIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "File.owner"`)
	}
	return nil
}

// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *FileUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *FileUpdateOne {
	_u.modifiers = append(_u.modifiers, modifiers...)
	return _u
}

func (_u *FileUpdateOne) sqlSave(ctx context.Context) (_node *File, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(file.Table, file.Columns, sqlgraph.NewFieldSpec(file.FieldID, field.TypeUint))
	id, ok := _u.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "File.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := _u.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, file.FieldID)
		for _, f := range fields {
			if !file.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != file.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := _u.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := _u.mutation.DeletedAt(); ok {
		_spec.SetField(file.FieldDeletedAt, field.TypeTime, value)
	}
	if _u.mutation.DeletedAtCleared() {
		_spec.ClearField(file.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(file.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.GetType(); ok {
		_spec.SetField(file.FieldType, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedType(); ok {
		_spec.AddField(file.FieldType, field.TypeInt, value)
	}
	if value, ok := _u.mutation.Name(); ok {
		_spec.SetField(file.FieldName, field.TypeString, value)
	}
	if value, ok := _u.mutation.Size(); ok {
		_spec.SetField(file.FieldSize, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedSize(); ok {
		_spec.AddField(file.FieldSize, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.ChildrenCount(); ok {
		_spec.SetField(file.FieldChildrenCount, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedChildrenCount(); ok {
		_spec.AddField(file.FieldChildrenCount, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.ViewConfig(); ok {
		_spec.SetField(file.FieldViewConfig, field.TypeString, value)
	}
	if _u.mutation.ViewConfigCleared() {
		_spec.ClearField(file.FieldViewConfig, field.TypeString)
	}
	if _u.mutation.OwnerCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   file.OwnerTable,
			Columns: []string{file.OwnerColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.OwnerIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   file.OwnerTable,
			Columns: []string{file.OwnerColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.ParentCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   file.ParentTable,
			Columns: []string{file.ParentColumn},
			Bidi:    true,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.ParentIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   file.ParentTable,
			Columns: []string{file.ParentColumn},
			Bidi:    true,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.ChildrenCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: true,
			Table:   file.ChildrenTable,
			Columns: []string{file.ChildrenColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedChildrenIDs(); len(nodes) > 0 && !_u.mutation.ChildrenCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: true,
			Table:   file.ChildrenTable,
			Columns: []string{file.ChildrenColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.ChildrenIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: true,
			Table:   file.ChildrenTable,
			Columns: []string{file.ChildrenColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.PrimaryEntityCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   file.PrimaryEntityTable,
			Columns: []string{file.PrimaryEntityColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.PrimaryEntityIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   file.PrimaryEntityTable,
			Columns: []string{file.PrimaryEntityColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.VersionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.VersionsTable,
			Columns: []string{file.VersionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(fileentity.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedVersionsIDs(); len(nodes) > 0 && !_u.mutation.VersionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.VersionsTable,
			Columns: []string{file.VersionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(fileentity.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.VersionsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.VersionsTable,
			Columns: []string{file.VersionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(fileentity.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.DirectLinkCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   file.DirectLinkTable,
			Columns: []string{file.DirectLinkColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(directlink.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.DirectLinkIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   file.DirectLinkTable,
			Columns: []string{file.DirectLinkColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(directlink.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.MetadataCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.MetadataTable,
			Columns: []string{file.MetadataColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(metadata.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedMetadataIDs(); len(nodes) > 0 && !_u.mutation.MetadataCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.MetadataTable,
			Columns: []string{file.MetadataColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(metadata.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.MetadataIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.MetadataTable,
			Columns: []string{file.MetadataColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(metadata.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_spec.AddModifiers(_u.modifiers...)
	_node = &File{config: _u.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{file.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	_u.mutation.done = true
	return _node, nil
}
