// 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/entity"
	"github.com/anzhiyu-c/anheyu-app/ent/file"
	"github.com/anzhiyu-c/anheyu-app/ent/fileentity"
	"github.com/anzhiyu-c/anheyu-app/ent/predicate"
)

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

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

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

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

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

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

// SetFileID sets the "file_id" field.
func (_u *FileEntityUpdate) SetFileID(v uint) *FileEntityUpdate {
	_u.mutation.SetFileID(v)
	return _u
}

// SetNillableFileID sets the "file_id" field if the given value is not nil.
func (_u *FileEntityUpdate) SetNillableFileID(v *uint) *FileEntityUpdate {
	if v != nil {
		_u.SetFileID(*v)
	}
	return _u
}

// SetEntityID sets the "entity_id" field.
func (_u *FileEntityUpdate) SetEntityID(v uint) *FileEntityUpdate {
	_u.mutation.SetEntityID(v)
	return _u
}

// SetNillableEntityID sets the "entity_id" field if the given value is not nil.
func (_u *FileEntityUpdate) SetNillableEntityID(v *uint) *FileEntityUpdate {
	if v != nil {
		_u.SetEntityID(*v)
	}
	return _u
}

// SetVersion sets the "version" field.
func (_u *FileEntityUpdate) SetVersion(v string) *FileEntityUpdate {
	_u.mutation.SetVersion(v)
	return _u
}

// SetNillableVersion sets the "version" field if the given value is not nil.
func (_u *FileEntityUpdate) SetNillableVersion(v *string) *FileEntityUpdate {
	if v != nil {
		_u.SetVersion(*v)
	}
	return _u
}

// ClearVersion clears the value of the "version" field.
func (_u *FileEntityUpdate) ClearVersion() *FileEntityUpdate {
	_u.mutation.ClearVersion()
	return _u
}

// SetIsCurrent sets the "is_current" field.
func (_u *FileEntityUpdate) SetIsCurrent(v bool) *FileEntityUpdate {
	_u.mutation.SetIsCurrent(v)
	return _u
}

// SetNillableIsCurrent sets the "is_current" field if the given value is not nil.
func (_u *FileEntityUpdate) SetNillableIsCurrent(v *bool) *FileEntityUpdate {
	if v != nil {
		_u.SetIsCurrent(*v)
	}
	return _u
}

// SetUploadedByUserID sets the "uploaded_by_user_id" field.
func (_u *FileEntityUpdate) SetUploadedByUserID(v uint64) *FileEntityUpdate {
	_u.mutation.ResetUploadedByUserID()
	_u.mutation.SetUploadedByUserID(v)
	return _u
}

// SetNillableUploadedByUserID sets the "uploaded_by_user_id" field if the given value is not nil.
func (_u *FileEntityUpdate) SetNillableUploadedByUserID(v *uint64) *FileEntityUpdate {
	if v != nil {
		_u.SetUploadedByUserID(*v)
	}
	return _u
}

// AddUploadedByUserID adds value to the "uploaded_by_user_id" field.
func (_u *FileEntityUpdate) AddUploadedByUserID(v int64) *FileEntityUpdate {
	_u.mutation.AddUploadedByUserID(v)
	return _u
}

// ClearUploadedByUserID clears the value of the "uploaded_by_user_id" field.
func (_u *FileEntityUpdate) ClearUploadedByUserID() *FileEntityUpdate {
	_u.mutation.ClearUploadedByUserID()
	return _u
}

// SetFile sets the "file" edge to the File entity.
func (_u *FileEntityUpdate) SetFile(v *File) *FileEntityUpdate {
	return _u.SetFileID(v.ID)
}

// SetEntity sets the "entity" edge to the Entity entity.
func (_u *FileEntityUpdate) SetEntity(v *Entity) *FileEntityUpdate {
	return _u.SetEntityID(v.ID)
}

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

// ClearFile clears the "file" edge to the File entity.
func (_u *FileEntityUpdate) ClearFile() *FileEntityUpdate {
	_u.mutation.ClearFile()
	return _u
}

// ClearEntity clears the "entity" edge to the Entity entity.
func (_u *FileEntityUpdate) ClearEntity() *FileEntityUpdate {
	_u.mutation.ClearEntity()
	return _u
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *FileEntityUpdate) 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 *FileEntityUpdate) SaveX(ctx context.Context) int {
	affected, err := _u.Save(ctx)
	if err != nil {
		panic(err)
	}
	return affected
}

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

// ExecX is like Exec, but panics if an error occurs.
func (_u *FileEntityUpdate) 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 *FileEntityUpdate) defaults() error {
	if _, ok := _u.mutation.UpdatedAt(); !ok {
		if fileentity.UpdateDefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized fileentity.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := fileentity.UpdateDefaultUpdatedAt()
		_u.mutation.SetUpdatedAt(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (_u *FileEntityUpdate) check() error {
	if v, ok := _u.mutation.Version(); ok {
		if err := fileentity.VersionValidator(v); err != nil {
			return &ValidationError{Name: "version", err: fmt.Errorf(`ent: validator failed for field "FileEntity.version": %w`, err)}
		}
	}
	if _u.mutation.FileCleared() && len(_u.mutation.FileIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "FileEntity.file"`)
	}
	if _u.mutation.EntityCleared() && len(_u.mutation.EntityIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "FileEntity.entity"`)
	}
	return nil
}

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

func (_u *FileEntityUpdate) sqlSave(ctx context.Context) (_node int, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(fileentity.Table, fileentity.Columns, sqlgraph.NewFieldSpec(fileentity.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(fileentity.FieldDeletedAt, field.TypeTime, value)
	}
	if _u.mutation.DeletedAtCleared() {
		_spec.ClearField(fileentity.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(fileentity.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.Version(); ok {
		_spec.SetField(fileentity.FieldVersion, field.TypeString, value)
	}
	if _u.mutation.VersionCleared() {
		_spec.ClearField(fileentity.FieldVersion, field.TypeString)
	}
	if value, ok := _u.mutation.IsCurrent(); ok {
		_spec.SetField(fileentity.FieldIsCurrent, field.TypeBool, value)
	}
	if value, ok := _u.mutation.UploadedByUserID(); ok {
		_spec.SetField(fileentity.FieldUploadedByUserID, field.TypeUint64, value)
	}
	if value, ok := _u.mutation.AddedUploadedByUserID(); ok {
		_spec.AddField(fileentity.FieldUploadedByUserID, field.TypeUint64, value)
	}
	if _u.mutation.UploadedByUserIDCleared() {
		_spec.ClearField(fileentity.FieldUploadedByUserID, field.TypeUint64)
	}
	if _u.mutation.FileCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   fileentity.FileTable,
			Columns: []string{fileentity.FileColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.FileIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   fileentity.FileTable,
			Columns: []string{fileentity.FileColumn},
			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.EntityCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   fileentity.EntityTable,
			Columns: []string{fileentity.EntityColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.EntityIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   fileentity.EntityTable,
			Columns: []string{fileentity.EntityColumn},
			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)
	}
	_spec.AddModifiers(_u.modifiers...)
	if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{fileentity.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	_u.mutation.done = true
	return _node, nil
}

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

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

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

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

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

// SetFileID sets the "file_id" field.
func (_u *FileEntityUpdateOne) SetFileID(v uint) *FileEntityUpdateOne {
	_u.mutation.SetFileID(v)
	return _u
}

// SetNillableFileID sets the "file_id" field if the given value is not nil.
func (_u *FileEntityUpdateOne) SetNillableFileID(v *uint) *FileEntityUpdateOne {
	if v != nil {
		_u.SetFileID(*v)
	}
	return _u
}

// SetEntityID sets the "entity_id" field.
func (_u *FileEntityUpdateOne) SetEntityID(v uint) *FileEntityUpdateOne {
	_u.mutation.SetEntityID(v)
	return _u
}

// SetNillableEntityID sets the "entity_id" field if the given value is not nil.
func (_u *FileEntityUpdateOne) SetNillableEntityID(v *uint) *FileEntityUpdateOne {
	if v != nil {
		_u.SetEntityID(*v)
	}
	return _u
}

// SetVersion sets the "version" field.
func (_u *FileEntityUpdateOne) SetVersion(v string) *FileEntityUpdateOne {
	_u.mutation.SetVersion(v)
	return _u
}

// SetNillableVersion sets the "version" field if the given value is not nil.
func (_u *FileEntityUpdateOne) SetNillableVersion(v *string) *FileEntityUpdateOne {
	if v != nil {
		_u.SetVersion(*v)
	}
	return _u
}

// ClearVersion clears the value of the "version" field.
func (_u *FileEntityUpdateOne) ClearVersion() *FileEntityUpdateOne {
	_u.mutation.ClearVersion()
	return _u
}

// SetIsCurrent sets the "is_current" field.
func (_u *FileEntityUpdateOne) SetIsCurrent(v bool) *FileEntityUpdateOne {
	_u.mutation.SetIsCurrent(v)
	return _u
}

// SetNillableIsCurrent sets the "is_current" field if the given value is not nil.
func (_u *FileEntityUpdateOne) SetNillableIsCurrent(v *bool) *FileEntityUpdateOne {
	if v != nil {
		_u.SetIsCurrent(*v)
	}
	return _u
}

// SetUploadedByUserID sets the "uploaded_by_user_id" field.
func (_u *FileEntityUpdateOne) SetUploadedByUserID(v uint64) *FileEntityUpdateOne {
	_u.mutation.ResetUploadedByUserID()
	_u.mutation.SetUploadedByUserID(v)
	return _u
}

// SetNillableUploadedByUserID sets the "uploaded_by_user_id" field if the given value is not nil.
func (_u *FileEntityUpdateOne) SetNillableUploadedByUserID(v *uint64) *FileEntityUpdateOne {
	if v != nil {
		_u.SetUploadedByUserID(*v)
	}
	return _u
}

// AddUploadedByUserID adds value to the "uploaded_by_user_id" field.
func (_u *FileEntityUpdateOne) AddUploadedByUserID(v int64) *FileEntityUpdateOne {
	_u.mutation.AddUploadedByUserID(v)
	return _u
}

// ClearUploadedByUserID clears the value of the "uploaded_by_user_id" field.
func (_u *FileEntityUpdateOne) ClearUploadedByUserID() *FileEntityUpdateOne {
	_u.mutation.ClearUploadedByUserID()
	return _u
}

// SetFile sets the "file" edge to the File entity.
func (_u *FileEntityUpdateOne) SetFile(v *File) *FileEntityUpdateOne {
	return _u.SetFileID(v.ID)
}

// SetEntity sets the "entity" edge to the Entity entity.
func (_u *FileEntityUpdateOne) SetEntity(v *Entity) *FileEntityUpdateOne {
	return _u.SetEntityID(v.ID)
}

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

// ClearFile clears the "file" edge to the File entity.
func (_u *FileEntityUpdateOne) ClearFile() *FileEntityUpdateOne {
	_u.mutation.ClearFile()
	return _u
}

// ClearEntity clears the "entity" edge to the Entity entity.
func (_u *FileEntityUpdateOne) ClearEntity() *FileEntityUpdateOne {
	_u.mutation.ClearEntity()
	return _u
}

// Where appends a list predicates to the FileEntityUpdate builder.
func (_u *FileEntityUpdateOne) Where(ps ...predicate.FileEntity) *FileEntityUpdateOne {
	_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 *FileEntityUpdateOne) Select(field string, fields ...string) *FileEntityUpdateOne {
	_u.fields = append([]string{field}, fields...)
	return _u
}

// Save executes the query and returns the updated FileEntity entity.
func (_u *FileEntityUpdateOne) Save(ctx context.Context) (*FileEntity, 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 *FileEntityUpdateOne) SaveX(ctx context.Context) *FileEntity {
	node, err := _u.Save(ctx)
	if err != nil {
		panic(err)
	}
	return node
}

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

// ExecX is like Exec, but panics if an error occurs.
func (_u *FileEntityUpdateOne) 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 *FileEntityUpdateOne) defaults() error {
	if _, ok := _u.mutation.UpdatedAt(); !ok {
		if fileentity.UpdateDefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized fileentity.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := fileentity.UpdateDefaultUpdatedAt()
		_u.mutation.SetUpdatedAt(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (_u *FileEntityUpdateOne) check() error {
	if v, ok := _u.mutation.Version(); ok {
		if err := fileentity.VersionValidator(v); err != nil {
			return &ValidationError{Name: "version", err: fmt.Errorf(`ent: validator failed for field "FileEntity.version": %w`, err)}
		}
	}
	if _u.mutation.FileCleared() && len(_u.mutation.FileIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "FileEntity.file"`)
	}
	if _u.mutation.EntityCleared() && len(_u.mutation.EntityIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "FileEntity.entity"`)
	}
	return nil
}

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

func (_u *FileEntityUpdateOne) sqlSave(ctx context.Context) (_node *FileEntity, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(fileentity.Table, fileentity.Columns, sqlgraph.NewFieldSpec(fileentity.FieldID, field.TypeUint))
	id, ok := _u.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "FileEntity.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, fileentity.FieldID)
		for _, f := range fields {
			if !fileentity.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != fileentity.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(fileentity.FieldDeletedAt, field.TypeTime, value)
	}
	if _u.mutation.DeletedAtCleared() {
		_spec.ClearField(fileentity.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(fileentity.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.Version(); ok {
		_spec.SetField(fileentity.FieldVersion, field.TypeString, value)
	}
	if _u.mutation.VersionCleared() {
		_spec.ClearField(fileentity.FieldVersion, field.TypeString)
	}
	if value, ok := _u.mutation.IsCurrent(); ok {
		_spec.SetField(fileentity.FieldIsCurrent, field.TypeBool, value)
	}
	if value, ok := _u.mutation.UploadedByUserID(); ok {
		_spec.SetField(fileentity.FieldUploadedByUserID, field.TypeUint64, value)
	}
	if value, ok := _u.mutation.AddedUploadedByUserID(); ok {
		_spec.AddField(fileentity.FieldUploadedByUserID, field.TypeUint64, value)
	}
	if _u.mutation.UploadedByUserIDCleared() {
		_spec.ClearField(fileentity.FieldUploadedByUserID, field.TypeUint64)
	}
	if _u.mutation.FileCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   fileentity.FileTable,
			Columns: []string{fileentity.FileColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.FileIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   fileentity.FileTable,
			Columns: []string{fileentity.FileColumn},
			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.EntityCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   fileentity.EntityTable,
			Columns: []string{fileentity.EntityColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.EntityIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   fileentity.EntityTable,
			Columns: []string{fileentity.EntityColumn},
			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)
	}
	_spec.AddModifiers(_u.modifiers...)
	_node = &FileEntity{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{fileentity.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	_u.mutation.done = true
	return _node, nil
}
