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

// ObjetUpdate is the builder for updating Objet entities.
type ObjetUpdate struct {
	config
	hooks    []Hook
	mutation *ObjetMutation
}

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

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

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

// SetDescription sets the "description" field.
func (_u *ObjetUpdate) SetDescription(v string) *ObjetUpdate {
	_u.mutation.SetDescription(v)
	return _u
}

// SetNillableDescription sets the "description" field if the given value is not nil.
func (_u *ObjetUpdate) SetNillableDescription(v *string) *ObjetUpdate {
	if v != nil {
		_u.SetDescription(*v)
	}
	return _u
}

// ClearDescription clears the value of the "description" field.
func (_u *ObjetUpdate) ClearDescription() *ObjetUpdate {
	_u.mutation.ClearDescription()
	return _u
}

// SetQuantite sets the "quantite" field.
func (_u *ObjetUpdate) SetQuantite(v int) *ObjetUpdate {
	_u.mutation.ResetQuantite()
	_u.mutation.SetQuantite(v)
	return _u
}

// SetNillableQuantite sets the "quantite" field if the given value is not nil.
func (_u *ObjetUpdate) SetNillableQuantite(v *int) *ObjetUpdate {
	if v != nil {
		_u.SetQuantite(*v)
	}
	return _u
}

// AddQuantite adds value to the "quantite" field.
func (_u *ObjetUpdate) AddQuantite(v int) *ObjetUpdate {
	_u.mutation.AddQuantite(v)
	return _u
}

// SetPrixAchat sets the "prix_achat" field.
func (_u *ObjetUpdate) SetPrixAchat(v float64) *ObjetUpdate {
	_u.mutation.ResetPrixAchat()
	_u.mutation.SetPrixAchat(v)
	return _u
}

// SetNillablePrixAchat sets the "prix_achat" field if the given value is not nil.
func (_u *ObjetUpdate) SetNillablePrixAchat(v *float64) *ObjetUpdate {
	if v != nil {
		_u.SetPrixAchat(*v)
	}
	return _u
}

// AddPrixAchat adds value to the "prix_achat" field.
func (_u *ObjetUpdate) AddPrixAchat(v float64) *ObjetUpdate {
	_u.mutation.AddPrixAchat(v)
	return _u
}

// ClearPrixAchat clears the value of the "prix_achat" field.
func (_u *ObjetUpdate) ClearPrixAchat() *ObjetUpdate {
	_u.mutation.ClearPrixAchat()
	return _u
}

// SetDateAchat sets the "date_achat" field.
func (_u *ObjetUpdate) SetDateAchat(v time.Time) *ObjetUpdate {
	_u.mutation.SetDateAchat(v)
	return _u
}

// SetNillableDateAchat sets the "date_achat" field if the given value is not nil.
func (_u *ObjetUpdate) SetNillableDateAchat(v *time.Time) *ObjetUpdate {
	if v != nil {
		_u.SetDateAchat(*v)
	}
	return _u
}

// ClearDateAchat clears the value of the "date_achat" field.
func (_u *ObjetUpdate) ClearDateAchat() *ObjetUpdate {
	_u.mutation.ClearDateAchat()
	return _u
}

// SetBoutique sets the "boutique" field.
func (_u *ObjetUpdate) SetBoutique(v string) *ObjetUpdate {
	_u.mutation.SetBoutique(v)
	return _u
}

// SetNillableBoutique sets the "boutique" field if the given value is not nil.
func (_u *ObjetUpdate) SetNillableBoutique(v *string) *ObjetUpdate {
	if v != nil {
		_u.SetBoutique(*v)
	}
	return _u
}

// ClearBoutique clears the value of the "boutique" field.
func (_u *ObjetUpdate) ClearBoutique() *ObjetUpdate {
	_u.mutation.ClearBoutique()
	return _u
}

// SetNumeroSerie sets the "numero_serie" field.
func (_u *ObjetUpdate) SetNumeroSerie(v string) *ObjetUpdate {
	_u.mutation.SetNumeroSerie(v)
	return _u
}

// SetNillableNumeroSerie sets the "numero_serie" field if the given value is not nil.
func (_u *ObjetUpdate) SetNillableNumeroSerie(v *string) *ObjetUpdate {
	if v != nil {
		_u.SetNumeroSerie(*v)
	}
	return _u
}

// ClearNumeroSerie clears the value of the "numero_serie" field.
func (_u *ObjetUpdate) ClearNumeroSerie() *ObjetUpdate {
	_u.mutation.ClearNumeroSerie()
	return _u
}

// SetNumeroModele sets the "numero_modele" field.
func (_u *ObjetUpdate) SetNumeroModele(v string) *ObjetUpdate {
	_u.mutation.SetNumeroModele(v)
	return _u
}

// SetNillableNumeroModele sets the "numero_modele" field if the given value is not nil.
func (_u *ObjetUpdate) SetNillableNumeroModele(v *string) *ObjetUpdate {
	if v != nil {
		_u.SetNumeroModele(*v)
	}
	return _u
}

// ClearNumeroModele clears the value of the "numero_modele" field.
func (_u *ObjetUpdate) ClearNumeroModele() *ObjetUpdate {
	_u.mutation.ClearNumeroModele()
	return _u
}

// SetFabricant sets the "fabricant" field.
func (_u *ObjetUpdate) SetFabricant(v string) *ObjetUpdate {
	_u.mutation.SetFabricant(v)
	return _u
}

// SetNillableFabricant sets the "fabricant" field if the given value is not nil.
func (_u *ObjetUpdate) SetNillableFabricant(v *string) *ObjetUpdate {
	if v != nil {
		_u.SetFabricant(*v)
	}
	return _u
}

// ClearFabricant clears the value of the "fabricant" field.
func (_u *ObjetUpdate) ClearFabricant() *ObjetUpdate {
	_u.mutation.ClearFabricant()
	return _u
}

// SetStatut sets the "statut" field.
func (_u *ObjetUpdate) SetStatut(v objet.Statut) *ObjetUpdate {
	_u.mutation.SetStatut(v)
	return _u
}

// SetNillableStatut sets the "statut" field if the given value is not nil.
func (_u *ObjetUpdate) SetNillableStatut(v *objet.Statut) *ObjetUpdate {
	if v != nil {
		_u.SetStatut(*v)
	}
	return _u
}

// SetCaracteristiques sets the "caracteristiques" field.
func (_u *ObjetUpdate) SetCaracteristiques(v map[string]interface{}) *ObjetUpdate {
	_u.mutation.SetCaracteristiques(v)
	return _u
}

// ClearCaracteristiques clears the value of the "caracteristiques" field.
func (_u *ObjetUpdate) ClearCaracteristiques() *ObjetUpdate {
	_u.mutation.ClearCaracteristiques()
	return _u
}

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

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

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

// AddLiensEmplacementIDs adds the "liens_emplacements" edge to the LienObjetEmplacement entity by IDs.
func (_u *ObjetUpdate) AddLiensEmplacementIDs(ids ...uuid.UUID) *ObjetUpdate {
	_u.mutation.AddLiensEmplacementIDs(ids...)
	return _u
}

// AddLiensEmplacements adds the "liens_emplacements" edges to the LienObjetEmplacement entity.
func (_u *ObjetUpdate) AddLiensEmplacements(v ...*LienObjetEmplacement) *ObjetUpdate {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddLiensEmplacementIDs(ids...)
}

// AddChampsPersonnaliseIDs adds the "champs_personnalises" edge to the ChampPersonnalise entity by IDs.
func (_u *ObjetUpdate) AddChampsPersonnaliseIDs(ids ...uuid.UUID) *ObjetUpdate {
	_u.mutation.AddChampsPersonnaliseIDs(ids...)
	return _u
}

// AddChampsPersonnalises adds the "champs_personnalises" edges to the ChampPersonnalise entity.
func (_u *ObjetUpdate) AddChampsPersonnalises(v ...*ChampPersonnalise) *ObjetUpdate {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddChampsPersonnaliseIDs(ids...)
}

// AddPiecesJointeIDs adds the "pieces_jointes" edge to the PieceJointe entity by IDs.
func (_u *ObjetUpdate) AddPiecesJointeIDs(ids ...uuid.UUID) *ObjetUpdate {
	_u.mutation.AddPiecesJointeIDs(ids...)
	return _u
}

// AddPiecesJointes adds the "pieces_jointes" edges to the PieceJointe entity.
func (_u *ObjetUpdate) AddPiecesJointes(v ...*PieceJointe) *ObjetUpdate {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddPiecesJointeIDs(ids...)
}

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

// ClearLiensEmplacements clears all "liens_emplacements" edges to the LienObjetEmplacement entity.
func (_u *ObjetUpdate) ClearLiensEmplacements() *ObjetUpdate {
	_u.mutation.ClearLiensEmplacements()
	return _u
}

// RemoveLiensEmplacementIDs removes the "liens_emplacements" edge to LienObjetEmplacement entities by IDs.
func (_u *ObjetUpdate) RemoveLiensEmplacementIDs(ids ...uuid.UUID) *ObjetUpdate {
	_u.mutation.RemoveLiensEmplacementIDs(ids...)
	return _u
}

// RemoveLiensEmplacements removes "liens_emplacements" edges to LienObjetEmplacement entities.
func (_u *ObjetUpdate) RemoveLiensEmplacements(v ...*LienObjetEmplacement) *ObjetUpdate {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveLiensEmplacementIDs(ids...)
}

// ClearChampsPersonnalises clears all "champs_personnalises" edges to the ChampPersonnalise entity.
func (_u *ObjetUpdate) ClearChampsPersonnalises() *ObjetUpdate {
	_u.mutation.ClearChampsPersonnalises()
	return _u
}

// RemoveChampsPersonnaliseIDs removes the "champs_personnalises" edge to ChampPersonnalise entities by IDs.
func (_u *ObjetUpdate) RemoveChampsPersonnaliseIDs(ids ...uuid.UUID) *ObjetUpdate {
	_u.mutation.RemoveChampsPersonnaliseIDs(ids...)
	return _u
}

// RemoveChampsPersonnalises removes "champs_personnalises" edges to ChampPersonnalise entities.
func (_u *ObjetUpdate) RemoveChampsPersonnalises(v ...*ChampPersonnalise) *ObjetUpdate {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveChampsPersonnaliseIDs(ids...)
}

// ClearPiecesJointes clears all "pieces_jointes" edges to the PieceJointe entity.
func (_u *ObjetUpdate) ClearPiecesJointes() *ObjetUpdate {
	_u.mutation.ClearPiecesJointes()
	return _u
}

// RemovePiecesJointeIDs removes the "pieces_jointes" edge to PieceJointe entities by IDs.
func (_u *ObjetUpdate) RemovePiecesJointeIDs(ids ...uuid.UUID) *ObjetUpdate {
	_u.mutation.RemovePiecesJointeIDs(ids...)
	return _u
}

// RemovePiecesJointes removes "pieces_jointes" edges to PieceJointe entities.
func (_u *ObjetUpdate) RemovePiecesJointes(v ...*PieceJointe) *ObjetUpdate {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemovePiecesJointeIDs(ids...)
}

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

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

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

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

func (_u *ObjetUpdate) sqlSave(ctx context.Context) (_node int, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(objet.Table, objet.Columns, sqlgraph.NewFieldSpec(objet.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(objet.FieldNom, field.TypeString, value)
	}
	if value, ok := _u.mutation.Description(); ok {
		_spec.SetField(objet.FieldDescription, field.TypeString, value)
	}
	if _u.mutation.DescriptionCleared() {
		_spec.ClearField(objet.FieldDescription, field.TypeString)
	}
	if value, ok := _u.mutation.Quantite(); ok {
		_spec.SetField(objet.FieldQuantite, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedQuantite(); ok {
		_spec.AddField(objet.FieldQuantite, field.TypeInt, value)
	}
	if value, ok := _u.mutation.PrixAchat(); ok {
		_spec.SetField(objet.FieldPrixAchat, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedPrixAchat(); ok {
		_spec.AddField(objet.FieldPrixAchat, field.TypeFloat64, value)
	}
	if _u.mutation.PrixAchatCleared() {
		_spec.ClearField(objet.FieldPrixAchat, field.TypeFloat64)
	}
	if value, ok := _u.mutation.DateAchat(); ok {
		_spec.SetField(objet.FieldDateAchat, field.TypeTime, value)
	}
	if _u.mutation.DateAchatCleared() {
		_spec.ClearField(objet.FieldDateAchat, field.TypeTime)
	}
	if value, ok := _u.mutation.Boutique(); ok {
		_spec.SetField(objet.FieldBoutique, field.TypeString, value)
	}
	if _u.mutation.BoutiqueCleared() {
		_spec.ClearField(objet.FieldBoutique, field.TypeString)
	}
	if value, ok := _u.mutation.NumeroSerie(); ok {
		_spec.SetField(objet.FieldNumeroSerie, field.TypeString, value)
	}
	if _u.mutation.NumeroSerieCleared() {
		_spec.ClearField(objet.FieldNumeroSerie, field.TypeString)
	}
	if value, ok := _u.mutation.NumeroModele(); ok {
		_spec.SetField(objet.FieldNumeroModele, field.TypeString, value)
	}
	if _u.mutation.NumeroModeleCleared() {
		_spec.ClearField(objet.FieldNumeroModele, field.TypeString)
	}
	if value, ok := _u.mutation.Fabricant(); ok {
		_spec.SetField(objet.FieldFabricant, field.TypeString, value)
	}
	if _u.mutation.FabricantCleared() {
		_spec.ClearField(objet.FieldFabricant, field.TypeString)
	}
	if value, ok := _u.mutation.Statut(); ok {
		_spec.SetField(objet.FieldStatut, field.TypeEnum, value)
	}
	if value, ok := _u.mutation.Caracteristiques(); ok {
		_spec.SetField(objet.FieldCaracteristiques, field.TypeJSON, value)
	}
	if _u.mutation.CaracteristiquesCleared() {
		_spec.ClearField(objet.FieldCaracteristiques, field.TypeJSON)
	}
	if value, ok := _u.mutation.CreatedAt(); ok {
		_spec.SetField(objet.FieldCreatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(objet.FieldUpdatedAt, field.TypeTime, value)
	}
	if _u.mutation.LiensEmplacementsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   objet.LiensEmplacementsTable,
			Columns: []string{objet.LiensEmplacementsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(lienobjetemplacement.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedLiensEmplacementsIDs(); len(nodes) > 0 && !_u.mutation.LiensEmplacementsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   objet.LiensEmplacementsTable,
			Columns: []string{objet.LiensEmplacementsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(lienobjetemplacement.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.LiensEmplacementsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   objet.LiensEmplacementsTable,
			Columns: []string{objet.LiensEmplacementsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(lienobjetemplacement.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.ChampsPersonnalisesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   objet.ChampsPersonnalisesTable,
			Columns: []string{objet.ChampsPersonnalisesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(champpersonnalise.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedChampsPersonnalisesIDs(); len(nodes) > 0 && !_u.mutation.ChampsPersonnalisesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   objet.ChampsPersonnalisesTable,
			Columns: []string{objet.ChampsPersonnalisesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(champpersonnalise.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.ChampsPersonnalisesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   objet.ChampsPersonnalisesTable,
			Columns: []string{objet.ChampsPersonnalisesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(champpersonnalise.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.PiecesJointesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   objet.PiecesJointesTable,
			Columns: []string{objet.PiecesJointesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(piecejointe.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedPiecesJointesIDs(); len(nodes) > 0 && !_u.mutation.PiecesJointesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   objet.PiecesJointesTable,
			Columns: []string{objet.PiecesJointesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(piecejointe.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.PiecesJointesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   objet.PiecesJointesTable,
			Columns: []string{objet.PiecesJointesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(piecejointe.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{objet.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	_u.mutation.done = true
	return _node, nil
}

// ObjetUpdateOne is the builder for updating a single Objet entity.
type ObjetUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *ObjetMutation
}

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

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

// SetDescription sets the "description" field.
func (_u *ObjetUpdateOne) SetDescription(v string) *ObjetUpdateOne {
	_u.mutation.SetDescription(v)
	return _u
}

// SetNillableDescription sets the "description" field if the given value is not nil.
func (_u *ObjetUpdateOne) SetNillableDescription(v *string) *ObjetUpdateOne {
	if v != nil {
		_u.SetDescription(*v)
	}
	return _u
}

// ClearDescription clears the value of the "description" field.
func (_u *ObjetUpdateOne) ClearDescription() *ObjetUpdateOne {
	_u.mutation.ClearDescription()
	return _u
}

// SetQuantite sets the "quantite" field.
func (_u *ObjetUpdateOne) SetQuantite(v int) *ObjetUpdateOne {
	_u.mutation.ResetQuantite()
	_u.mutation.SetQuantite(v)
	return _u
}

// SetNillableQuantite sets the "quantite" field if the given value is not nil.
func (_u *ObjetUpdateOne) SetNillableQuantite(v *int) *ObjetUpdateOne {
	if v != nil {
		_u.SetQuantite(*v)
	}
	return _u
}

// AddQuantite adds value to the "quantite" field.
func (_u *ObjetUpdateOne) AddQuantite(v int) *ObjetUpdateOne {
	_u.mutation.AddQuantite(v)
	return _u
}

// SetPrixAchat sets the "prix_achat" field.
func (_u *ObjetUpdateOne) SetPrixAchat(v float64) *ObjetUpdateOne {
	_u.mutation.ResetPrixAchat()
	_u.mutation.SetPrixAchat(v)
	return _u
}

// SetNillablePrixAchat sets the "prix_achat" field if the given value is not nil.
func (_u *ObjetUpdateOne) SetNillablePrixAchat(v *float64) *ObjetUpdateOne {
	if v != nil {
		_u.SetPrixAchat(*v)
	}
	return _u
}

// AddPrixAchat adds value to the "prix_achat" field.
func (_u *ObjetUpdateOne) AddPrixAchat(v float64) *ObjetUpdateOne {
	_u.mutation.AddPrixAchat(v)
	return _u
}

// ClearPrixAchat clears the value of the "prix_achat" field.
func (_u *ObjetUpdateOne) ClearPrixAchat() *ObjetUpdateOne {
	_u.mutation.ClearPrixAchat()
	return _u
}

// SetDateAchat sets the "date_achat" field.
func (_u *ObjetUpdateOne) SetDateAchat(v time.Time) *ObjetUpdateOne {
	_u.mutation.SetDateAchat(v)
	return _u
}

// SetNillableDateAchat sets the "date_achat" field if the given value is not nil.
func (_u *ObjetUpdateOne) SetNillableDateAchat(v *time.Time) *ObjetUpdateOne {
	if v != nil {
		_u.SetDateAchat(*v)
	}
	return _u
}

// ClearDateAchat clears the value of the "date_achat" field.
func (_u *ObjetUpdateOne) ClearDateAchat() *ObjetUpdateOne {
	_u.mutation.ClearDateAchat()
	return _u
}

// SetBoutique sets the "boutique" field.
func (_u *ObjetUpdateOne) SetBoutique(v string) *ObjetUpdateOne {
	_u.mutation.SetBoutique(v)
	return _u
}

// SetNillableBoutique sets the "boutique" field if the given value is not nil.
func (_u *ObjetUpdateOne) SetNillableBoutique(v *string) *ObjetUpdateOne {
	if v != nil {
		_u.SetBoutique(*v)
	}
	return _u
}

// ClearBoutique clears the value of the "boutique" field.
func (_u *ObjetUpdateOne) ClearBoutique() *ObjetUpdateOne {
	_u.mutation.ClearBoutique()
	return _u
}

// SetNumeroSerie sets the "numero_serie" field.
func (_u *ObjetUpdateOne) SetNumeroSerie(v string) *ObjetUpdateOne {
	_u.mutation.SetNumeroSerie(v)
	return _u
}

// SetNillableNumeroSerie sets the "numero_serie" field if the given value is not nil.
func (_u *ObjetUpdateOne) SetNillableNumeroSerie(v *string) *ObjetUpdateOne {
	if v != nil {
		_u.SetNumeroSerie(*v)
	}
	return _u
}

// ClearNumeroSerie clears the value of the "numero_serie" field.
func (_u *ObjetUpdateOne) ClearNumeroSerie() *ObjetUpdateOne {
	_u.mutation.ClearNumeroSerie()
	return _u
}

// SetNumeroModele sets the "numero_modele" field.
func (_u *ObjetUpdateOne) SetNumeroModele(v string) *ObjetUpdateOne {
	_u.mutation.SetNumeroModele(v)
	return _u
}

// SetNillableNumeroModele sets the "numero_modele" field if the given value is not nil.
func (_u *ObjetUpdateOne) SetNillableNumeroModele(v *string) *ObjetUpdateOne {
	if v != nil {
		_u.SetNumeroModele(*v)
	}
	return _u
}

// ClearNumeroModele clears the value of the "numero_modele" field.
func (_u *ObjetUpdateOne) ClearNumeroModele() *ObjetUpdateOne {
	_u.mutation.ClearNumeroModele()
	return _u
}

// SetFabricant sets the "fabricant" field.
func (_u *ObjetUpdateOne) SetFabricant(v string) *ObjetUpdateOne {
	_u.mutation.SetFabricant(v)
	return _u
}

// SetNillableFabricant sets the "fabricant" field if the given value is not nil.
func (_u *ObjetUpdateOne) SetNillableFabricant(v *string) *ObjetUpdateOne {
	if v != nil {
		_u.SetFabricant(*v)
	}
	return _u
}

// ClearFabricant clears the value of the "fabricant" field.
func (_u *ObjetUpdateOne) ClearFabricant() *ObjetUpdateOne {
	_u.mutation.ClearFabricant()
	return _u
}

// SetStatut sets the "statut" field.
func (_u *ObjetUpdateOne) SetStatut(v objet.Statut) *ObjetUpdateOne {
	_u.mutation.SetStatut(v)
	return _u
}

// SetNillableStatut sets the "statut" field if the given value is not nil.
func (_u *ObjetUpdateOne) SetNillableStatut(v *objet.Statut) *ObjetUpdateOne {
	if v != nil {
		_u.SetStatut(*v)
	}
	return _u
}

// SetCaracteristiques sets the "caracteristiques" field.
func (_u *ObjetUpdateOne) SetCaracteristiques(v map[string]interface{}) *ObjetUpdateOne {
	_u.mutation.SetCaracteristiques(v)
	return _u
}

// ClearCaracteristiques clears the value of the "caracteristiques" field.
func (_u *ObjetUpdateOne) ClearCaracteristiques() *ObjetUpdateOne {
	_u.mutation.ClearCaracteristiques()
	return _u
}

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

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

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

// AddLiensEmplacementIDs adds the "liens_emplacements" edge to the LienObjetEmplacement entity by IDs.
func (_u *ObjetUpdateOne) AddLiensEmplacementIDs(ids ...uuid.UUID) *ObjetUpdateOne {
	_u.mutation.AddLiensEmplacementIDs(ids...)
	return _u
}

// AddLiensEmplacements adds the "liens_emplacements" edges to the LienObjetEmplacement entity.
func (_u *ObjetUpdateOne) AddLiensEmplacements(v ...*LienObjetEmplacement) *ObjetUpdateOne {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddLiensEmplacementIDs(ids...)
}

// AddChampsPersonnaliseIDs adds the "champs_personnalises" edge to the ChampPersonnalise entity by IDs.
func (_u *ObjetUpdateOne) AddChampsPersonnaliseIDs(ids ...uuid.UUID) *ObjetUpdateOne {
	_u.mutation.AddChampsPersonnaliseIDs(ids...)
	return _u
}

// AddChampsPersonnalises adds the "champs_personnalises" edges to the ChampPersonnalise entity.
func (_u *ObjetUpdateOne) AddChampsPersonnalises(v ...*ChampPersonnalise) *ObjetUpdateOne {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddChampsPersonnaliseIDs(ids...)
}

// AddPiecesJointeIDs adds the "pieces_jointes" edge to the PieceJointe entity by IDs.
func (_u *ObjetUpdateOne) AddPiecesJointeIDs(ids ...uuid.UUID) *ObjetUpdateOne {
	_u.mutation.AddPiecesJointeIDs(ids...)
	return _u
}

// AddPiecesJointes adds the "pieces_jointes" edges to the PieceJointe entity.
func (_u *ObjetUpdateOne) AddPiecesJointes(v ...*PieceJointe) *ObjetUpdateOne {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddPiecesJointeIDs(ids...)
}

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

// ClearLiensEmplacements clears all "liens_emplacements" edges to the LienObjetEmplacement entity.
func (_u *ObjetUpdateOne) ClearLiensEmplacements() *ObjetUpdateOne {
	_u.mutation.ClearLiensEmplacements()
	return _u
}

// RemoveLiensEmplacementIDs removes the "liens_emplacements" edge to LienObjetEmplacement entities by IDs.
func (_u *ObjetUpdateOne) RemoveLiensEmplacementIDs(ids ...uuid.UUID) *ObjetUpdateOne {
	_u.mutation.RemoveLiensEmplacementIDs(ids...)
	return _u
}

// RemoveLiensEmplacements removes "liens_emplacements" edges to LienObjetEmplacement entities.
func (_u *ObjetUpdateOne) RemoveLiensEmplacements(v ...*LienObjetEmplacement) *ObjetUpdateOne {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveLiensEmplacementIDs(ids...)
}

// ClearChampsPersonnalises clears all "champs_personnalises" edges to the ChampPersonnalise entity.
func (_u *ObjetUpdateOne) ClearChampsPersonnalises() *ObjetUpdateOne {
	_u.mutation.ClearChampsPersonnalises()
	return _u
}

// RemoveChampsPersonnaliseIDs removes the "champs_personnalises" edge to ChampPersonnalise entities by IDs.
func (_u *ObjetUpdateOne) RemoveChampsPersonnaliseIDs(ids ...uuid.UUID) *ObjetUpdateOne {
	_u.mutation.RemoveChampsPersonnaliseIDs(ids...)
	return _u
}

// RemoveChampsPersonnalises removes "champs_personnalises" edges to ChampPersonnalise entities.
func (_u *ObjetUpdateOne) RemoveChampsPersonnalises(v ...*ChampPersonnalise) *ObjetUpdateOne {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveChampsPersonnaliseIDs(ids...)
}

// ClearPiecesJointes clears all "pieces_jointes" edges to the PieceJointe entity.
func (_u *ObjetUpdateOne) ClearPiecesJointes() *ObjetUpdateOne {
	_u.mutation.ClearPiecesJointes()
	return _u
}

// RemovePiecesJointeIDs removes the "pieces_jointes" edge to PieceJointe entities by IDs.
func (_u *ObjetUpdateOne) RemovePiecesJointeIDs(ids ...uuid.UUID) *ObjetUpdateOne {
	_u.mutation.RemovePiecesJointeIDs(ids...)
	return _u
}

// RemovePiecesJointes removes "pieces_jointes" edges to PieceJointe entities.
func (_u *ObjetUpdateOne) RemovePiecesJointes(v ...*PieceJointe) *ObjetUpdateOne {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemovePiecesJointeIDs(ids...)
}

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

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

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

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

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

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

func (_u *ObjetUpdateOne) sqlSave(ctx context.Context) (_node *Objet, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(objet.Table, objet.Columns, sqlgraph.NewFieldSpec(objet.FieldID, field.TypeUUID))
	id, ok := _u.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Objet.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, objet.FieldID)
		for _, f := range fields {
			if !objet.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != objet.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(objet.FieldNom, field.TypeString, value)
	}
	if value, ok := _u.mutation.Description(); ok {
		_spec.SetField(objet.FieldDescription, field.TypeString, value)
	}
	if _u.mutation.DescriptionCleared() {
		_spec.ClearField(objet.FieldDescription, field.TypeString)
	}
	if value, ok := _u.mutation.Quantite(); ok {
		_spec.SetField(objet.FieldQuantite, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedQuantite(); ok {
		_spec.AddField(objet.FieldQuantite, field.TypeInt, value)
	}
	if value, ok := _u.mutation.PrixAchat(); ok {
		_spec.SetField(objet.FieldPrixAchat, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedPrixAchat(); ok {
		_spec.AddField(objet.FieldPrixAchat, field.TypeFloat64, value)
	}
	if _u.mutation.PrixAchatCleared() {
		_spec.ClearField(objet.FieldPrixAchat, field.TypeFloat64)
	}
	if value, ok := _u.mutation.DateAchat(); ok {
		_spec.SetField(objet.FieldDateAchat, field.TypeTime, value)
	}
	if _u.mutation.DateAchatCleared() {
		_spec.ClearField(objet.FieldDateAchat, field.TypeTime)
	}
	if value, ok := _u.mutation.Boutique(); ok {
		_spec.SetField(objet.FieldBoutique, field.TypeString, value)
	}
	if _u.mutation.BoutiqueCleared() {
		_spec.ClearField(objet.FieldBoutique, field.TypeString)
	}
	if value, ok := _u.mutation.NumeroSerie(); ok {
		_spec.SetField(objet.FieldNumeroSerie, field.TypeString, value)
	}
	if _u.mutation.NumeroSerieCleared() {
		_spec.ClearField(objet.FieldNumeroSerie, field.TypeString)
	}
	if value, ok := _u.mutation.NumeroModele(); ok {
		_spec.SetField(objet.FieldNumeroModele, field.TypeString, value)
	}
	if _u.mutation.NumeroModeleCleared() {
		_spec.ClearField(objet.FieldNumeroModele, field.TypeString)
	}
	if value, ok := _u.mutation.Fabricant(); ok {
		_spec.SetField(objet.FieldFabricant, field.TypeString, value)
	}
	if _u.mutation.FabricantCleared() {
		_spec.ClearField(objet.FieldFabricant, field.TypeString)
	}
	if value, ok := _u.mutation.Statut(); ok {
		_spec.SetField(objet.FieldStatut, field.TypeEnum, value)
	}
	if value, ok := _u.mutation.Caracteristiques(); ok {
		_spec.SetField(objet.FieldCaracteristiques, field.TypeJSON, value)
	}
	if _u.mutation.CaracteristiquesCleared() {
		_spec.ClearField(objet.FieldCaracteristiques, field.TypeJSON)
	}
	if value, ok := _u.mutation.CreatedAt(); ok {
		_spec.SetField(objet.FieldCreatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(objet.FieldUpdatedAt, field.TypeTime, value)
	}
	if _u.mutation.LiensEmplacementsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   objet.LiensEmplacementsTable,
			Columns: []string{objet.LiensEmplacementsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(lienobjetemplacement.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedLiensEmplacementsIDs(); len(nodes) > 0 && !_u.mutation.LiensEmplacementsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   objet.LiensEmplacementsTable,
			Columns: []string{objet.LiensEmplacementsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(lienobjetemplacement.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.LiensEmplacementsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   objet.LiensEmplacementsTable,
			Columns: []string{objet.LiensEmplacementsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(lienobjetemplacement.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.ChampsPersonnalisesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   objet.ChampsPersonnalisesTable,
			Columns: []string{objet.ChampsPersonnalisesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(champpersonnalise.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedChampsPersonnalisesIDs(); len(nodes) > 0 && !_u.mutation.ChampsPersonnalisesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   objet.ChampsPersonnalisesTable,
			Columns: []string{objet.ChampsPersonnalisesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(champpersonnalise.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.ChampsPersonnalisesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   objet.ChampsPersonnalisesTable,
			Columns: []string{objet.ChampsPersonnalisesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(champpersonnalise.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.PiecesJointesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   objet.PiecesJointesTable,
			Columns: []string{objet.PiecesJointesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(piecejointe.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedPiecesJointesIDs(); len(nodes) > 0 && !_u.mutation.PiecesJointesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   objet.PiecesJointesTable,
			Columns: []string{objet.PiecesJointesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(piecejointe.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.PiecesJointesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   objet.PiecesJointesTable,
			Columns: []string{objet.PiecesJointesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(piecejointe.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &Objet{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{objet.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	_u.mutation.done = true
	return _node, nil
}
