// 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"
	"gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/categorie"
	"gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/predicate"
	"github.com/google/uuid"
)

// CategorieUpdate is the builder for updating Categorie entities.
type CategorieUpdate struct {
	config
	hooks    []Hook
	mutation *CategorieMutation
}

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

// SetNom sets the "nom" field.
func (_u *CategorieUpdate) SetNom(v string) *CategorieUpdate {
	_u.mutation.SetNom(v)
	return _u
}

// SetNillableNom sets the "nom" field if the given value is not nil.
func (_u *CategorieUpdate) SetNillableNom(v *string) *CategorieUpdate {
	if v != nil {
		_u.SetNom(*v)
	}
	return _u
}

// SetParentID sets the "parent_id" field.
func (_u *CategorieUpdate) SetParentID(v uuid.UUID) *CategorieUpdate {
	_u.mutation.SetParentID(v)
	return _u
}

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

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

// SetSlug sets the "slug" field.
func (_u *CategorieUpdate) SetSlug(v string) *CategorieUpdate {
	_u.mutation.SetSlug(v)
	return _u
}

// SetNillableSlug sets the "slug" field if the given value is not nil.
func (_u *CategorieUpdate) SetNillableSlug(v *string) *CategorieUpdate {
	if v != nil {
		_u.SetSlug(*v)
	}
	return _u
}

// ClearSlug clears the value of the "slug" field.
func (_u *CategorieUpdate) ClearSlug() *CategorieUpdate {
	_u.mutation.ClearSlug()
	return _u
}

// SetIcone sets the "icone" field.
func (_u *CategorieUpdate) SetIcone(v string) *CategorieUpdate {
	_u.mutation.SetIcone(v)
	return _u
}

// SetNillableIcone sets the "icone" field if the given value is not nil.
func (_u *CategorieUpdate) SetNillableIcone(v *string) *CategorieUpdate {
	if v != nil {
		_u.SetIcone(*v)
	}
	return _u
}

// ClearIcone clears the value of the "icone" field.
func (_u *CategorieUpdate) ClearIcone() *CategorieUpdate {
	_u.mutation.ClearIcone()
	return _u
}

// SetCreatedAt sets the "created_at" field.
func (_u *CategorieUpdate) SetCreatedAt(v time.Time) *CategorieUpdate {
	_u.mutation.SetCreatedAt(v)
	return _u
}

// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *CategorieUpdate) SetNillableCreatedAt(v *time.Time) *CategorieUpdate {
	if v != nil {
		_u.SetCreatedAt(*v)
	}
	return _u
}

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

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

// AddEnfantIDs adds the "enfants" edge to the Categorie entity by IDs.
func (_u *CategorieUpdate) AddEnfantIDs(ids ...uuid.UUID) *CategorieUpdate {
	_u.mutation.AddEnfantIDs(ids...)
	return _u
}

// AddEnfants adds the "enfants" edges to the Categorie entity.
func (_u *CategorieUpdate) AddEnfants(v ...*Categorie) *CategorieUpdate {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddEnfantIDs(ids...)
}

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

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

// ClearEnfants clears all "enfants" edges to the Categorie entity.
func (_u *CategorieUpdate) ClearEnfants() *CategorieUpdate {
	_u.mutation.ClearEnfants()
	return _u
}

// RemoveEnfantIDs removes the "enfants" edge to Categorie entities by IDs.
func (_u *CategorieUpdate) RemoveEnfantIDs(ids ...uuid.UUID) *CategorieUpdate {
	_u.mutation.RemoveEnfantIDs(ids...)
	return _u
}

// RemoveEnfants removes "enfants" edges to Categorie entities.
func (_u *CategorieUpdate) RemoveEnfants(v ...*Categorie) *CategorieUpdate {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveEnfantIDs(ids...)
}

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

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

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

// ExecX is like Exec, but panics if an error occurs.
func (_u *CategorieUpdate) 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 *CategorieUpdate) defaults() {
	if _, ok := _u.mutation.UpdatedAt(); !ok {
		v := categorie.UpdateDefaultUpdatedAt()
		_u.mutation.SetUpdatedAt(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (_u *CategorieUpdate) check() error {
	if v, ok := _u.mutation.Nom(); ok {
		if err := categorie.NomValidator(v); err != nil {
			return &ValidationError{Name: "nom", err: fmt.Errorf(`ent: validator failed for field "Categorie.nom": %w`, err)}
		}
	}
	return nil
}

func (_u *CategorieUpdate) sqlSave(ctx context.Context) (_node int, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(categorie.Table, categorie.Columns, sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID))
	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.Nom(); ok {
		_spec.SetField(categorie.FieldNom, field.TypeString, value)
	}
	if value, ok := _u.mutation.Slug(); ok {
		_spec.SetField(categorie.FieldSlug, field.TypeString, value)
	}
	if _u.mutation.SlugCleared() {
		_spec.ClearField(categorie.FieldSlug, field.TypeString)
	}
	if value, ok := _u.mutation.Icone(); ok {
		_spec.SetField(categorie.FieldIcone, field.TypeString, value)
	}
	if _u.mutation.IconeCleared() {
		_spec.ClearField(categorie.FieldIcone, field.TypeString)
	}
	if value, ok := _u.mutation.CreatedAt(); ok {
		_spec.SetField(categorie.FieldCreatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(categorie.FieldUpdatedAt, field.TypeTime, value)
	}
	if _u.mutation.ParentCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   categorie.ParentTable,
			Columns: []string{categorie.ParentColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.ParentIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   categorie.ParentTable,
			Columns: []string{categorie.ParentColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.EnfantsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   categorie.EnfantsTable,
			Columns: []string{categorie.EnfantsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedEnfantsIDs(); len(nodes) > 0 && !_u.mutation.EnfantsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   categorie.EnfantsTable,
			Columns: []string{categorie.EnfantsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.EnfantsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   categorie.EnfantsTable,
			Columns: []string{categorie.EnfantsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{categorie.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	_u.mutation.done = true
	return _node, nil
}

// CategorieUpdateOne is the builder for updating a single Categorie entity.
type CategorieUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *CategorieMutation
}

// SetNom sets the "nom" field.
func (_u *CategorieUpdateOne) SetNom(v string) *CategorieUpdateOne {
	_u.mutation.SetNom(v)
	return _u
}

// SetNillableNom sets the "nom" field if the given value is not nil.
func (_u *CategorieUpdateOne) SetNillableNom(v *string) *CategorieUpdateOne {
	if v != nil {
		_u.SetNom(*v)
	}
	return _u
}

// SetParentID sets the "parent_id" field.
func (_u *CategorieUpdateOne) SetParentID(v uuid.UUID) *CategorieUpdateOne {
	_u.mutation.SetParentID(v)
	return _u
}

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

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

// SetSlug sets the "slug" field.
func (_u *CategorieUpdateOne) SetSlug(v string) *CategorieUpdateOne {
	_u.mutation.SetSlug(v)
	return _u
}

// SetNillableSlug sets the "slug" field if the given value is not nil.
func (_u *CategorieUpdateOne) SetNillableSlug(v *string) *CategorieUpdateOne {
	if v != nil {
		_u.SetSlug(*v)
	}
	return _u
}

// ClearSlug clears the value of the "slug" field.
func (_u *CategorieUpdateOne) ClearSlug() *CategorieUpdateOne {
	_u.mutation.ClearSlug()
	return _u
}

// SetIcone sets the "icone" field.
func (_u *CategorieUpdateOne) SetIcone(v string) *CategorieUpdateOne {
	_u.mutation.SetIcone(v)
	return _u
}

// SetNillableIcone sets the "icone" field if the given value is not nil.
func (_u *CategorieUpdateOne) SetNillableIcone(v *string) *CategorieUpdateOne {
	if v != nil {
		_u.SetIcone(*v)
	}
	return _u
}

// ClearIcone clears the value of the "icone" field.
func (_u *CategorieUpdateOne) ClearIcone() *CategorieUpdateOne {
	_u.mutation.ClearIcone()
	return _u
}

// SetCreatedAt sets the "created_at" field.
func (_u *CategorieUpdateOne) SetCreatedAt(v time.Time) *CategorieUpdateOne {
	_u.mutation.SetCreatedAt(v)
	return _u
}

// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *CategorieUpdateOne) SetNillableCreatedAt(v *time.Time) *CategorieUpdateOne {
	if v != nil {
		_u.SetCreatedAt(*v)
	}
	return _u
}

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

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

// AddEnfantIDs adds the "enfants" edge to the Categorie entity by IDs.
func (_u *CategorieUpdateOne) AddEnfantIDs(ids ...uuid.UUID) *CategorieUpdateOne {
	_u.mutation.AddEnfantIDs(ids...)
	return _u
}

// AddEnfants adds the "enfants" edges to the Categorie entity.
func (_u *CategorieUpdateOne) AddEnfants(v ...*Categorie) *CategorieUpdateOne {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddEnfantIDs(ids...)
}

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

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

// ClearEnfants clears all "enfants" edges to the Categorie entity.
func (_u *CategorieUpdateOne) ClearEnfants() *CategorieUpdateOne {
	_u.mutation.ClearEnfants()
	return _u
}

// RemoveEnfantIDs removes the "enfants" edge to Categorie entities by IDs.
func (_u *CategorieUpdateOne) RemoveEnfantIDs(ids ...uuid.UUID) *CategorieUpdateOne {
	_u.mutation.RemoveEnfantIDs(ids...)
	return _u
}

// RemoveEnfants removes "enfants" edges to Categorie entities.
func (_u *CategorieUpdateOne) RemoveEnfants(v ...*Categorie) *CategorieUpdateOne {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveEnfantIDs(ids...)
}

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

// Save executes the query and returns the updated Categorie entity.
func (_u *CategorieUpdateOne) Save(ctx context.Context) (*Categorie, error) {
	_u.defaults()
	return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}

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

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

// ExecX is like Exec, but panics if an error occurs.
func (_u *CategorieUpdateOne) 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 *CategorieUpdateOne) defaults() {
	if _, ok := _u.mutation.UpdatedAt(); !ok {
		v := categorie.UpdateDefaultUpdatedAt()
		_u.mutation.SetUpdatedAt(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (_u *CategorieUpdateOne) check() error {
	if v, ok := _u.mutation.Nom(); ok {
		if err := categorie.NomValidator(v); err != nil {
			return &ValidationError{Name: "nom", err: fmt.Errorf(`ent: validator failed for field "Categorie.nom": %w`, err)}
		}
	}
	return nil
}

func (_u *CategorieUpdateOne) sqlSave(ctx context.Context) (_node *Categorie, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(categorie.Table, categorie.Columns, sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID))
	id, ok := _u.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Categorie.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, categorie.FieldID)
		for _, f := range fields {
			if !categorie.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != categorie.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.Nom(); ok {
		_spec.SetField(categorie.FieldNom, field.TypeString, value)
	}
	if value, ok := _u.mutation.Slug(); ok {
		_spec.SetField(categorie.FieldSlug, field.TypeString, value)
	}
	if _u.mutation.SlugCleared() {
		_spec.ClearField(categorie.FieldSlug, field.TypeString)
	}
	if value, ok := _u.mutation.Icone(); ok {
		_spec.SetField(categorie.FieldIcone, field.TypeString, value)
	}
	if _u.mutation.IconeCleared() {
		_spec.ClearField(categorie.FieldIcone, field.TypeString)
	}
	if value, ok := _u.mutation.CreatedAt(); ok {
		_spec.SetField(categorie.FieldCreatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(categorie.FieldUpdatedAt, field.TypeTime, value)
	}
	if _u.mutation.ParentCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   categorie.ParentTable,
			Columns: []string{categorie.ParentColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.ParentIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   categorie.ParentTable,
			Columns: []string{categorie.ParentColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.EnfantsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   categorie.EnfantsTable,
			Columns: []string{categorie.EnfantsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedEnfantsIDs(); len(nodes) > 0 && !_u.mutation.EnfantsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   categorie.EnfantsTable,
			Columns: []string{categorie.EnfantsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.EnfantsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   categorie.EnfantsTable,
			Columns: []string{categorie.EnfantsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(categorie.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &Categorie{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{categorie.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	_u.mutation.done = true
	return _node, nil
}
