// Copyright 2019-present Facebook Inc. All rights reserved. // This source code is licensed under the Apache 2.0 license found // in the LICENSE file in the root directory of this source tree. // Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/entc/integration/hooks/ent/card" "entgo.io/ent/entc/integration/hooks/ent/pet" "entgo.io/ent/entc/integration/hooks/ent/predicate" "entgo.io/ent/entc/integration/hooks/ent/user" "entgo.io/ent/schema/field" ) // UserUpdate is the builder for updating User entities. type UserUpdate struct { config hooks []Hook mutation *UserMutation } // Where appends a list predicates to the UserUpdate builder. func (_u *UserUpdate) Where(ps ...predicate.User) *UserUpdate { _u.mutation.Where(ps...) return _u } // SetVersion sets the "version" field. func (_u *UserUpdate) SetVersion(v int) *UserUpdate { _u.mutation.ResetVersion() _u.mutation.SetVersion(v) return _u } // SetNillableVersion sets the "version" field if the given value is not nil. func (_u *UserUpdate) SetNillableVersion(v *int) *UserUpdate { if v != nil { _u.SetVersion(*v) } return _u } // AddVersion adds value to the "version" field. func (_u *UserUpdate) AddVersion(v int) *UserUpdate { _u.mutation.AddVersion(v) return _u } // SetName sets the "name" field. func (_u *UserUpdate) SetName(v string) *UserUpdate { _u.mutation.SetName(v) return _u } // SetNillableName sets the "name" field if the given value is not nil. func (_u *UserUpdate) SetNillableName(v *string) *UserUpdate { if v != nil { _u.SetName(*v) } return _u } // SetWorth sets the "worth" field. func (_u *UserUpdate) SetWorth(v uint) *UserUpdate { _u.mutation.ResetWorth() _u.mutation.SetWorth(v) return _u } // SetNillableWorth sets the "worth" field if the given value is not nil. func (_u *UserUpdate) SetNillableWorth(v *uint) *UserUpdate { if v != nil { _u.SetWorth(*v) } return _u } // AddWorth adds value to the "worth" field. func (_u *UserUpdate) AddWorth(v int) *UserUpdate { _u.mutation.AddWorth(v) return _u } // ClearWorth clears the value of the "worth" field. func (_u *UserUpdate) ClearWorth() *UserUpdate { _u.mutation.ClearWorth() return _u } // SetPassword sets the "password" field. func (_u *UserUpdate) SetPassword(v string) *UserUpdate { _u.mutation.SetPassword(v) return _u } // SetNillablePassword sets the "password" field if the given value is not nil. func (_u *UserUpdate) SetNillablePassword(v *string) *UserUpdate { if v != nil { _u.SetPassword(*v) } return _u } // ClearPassword clears the value of the "password" field. func (_u *UserUpdate) ClearPassword() *UserUpdate { _u.mutation.ClearPassword() return _u } // SetActive sets the "active" field. func (_u *UserUpdate) SetActive(v bool) *UserUpdate { _u.mutation.SetActive(v) return _u } // SetNillableActive sets the "active" field if the given value is not nil. func (_u *UserUpdate) SetNillableActive(v *bool) *UserUpdate { if v != nil { _u.SetActive(*v) } return _u } // AddCardIDs adds the "cards" edge to the Card entity by IDs. func (_u *UserUpdate) AddCardIDs(ids ...int) *UserUpdate { _u.mutation.AddCardIDs(ids...) return _u } // AddCards adds the "cards" edges to the Card entity. func (_u *UserUpdate) AddCards(v ...*Card) *UserUpdate { ids := make([]int, len(v)) for i := range v { ids[i] = v[i].ID } return _u.AddCardIDs(ids...) } // AddPetIDs adds the "pets" edge to the Pet entity by IDs. func (_u *UserUpdate) AddPetIDs(ids ...int) *UserUpdate { _u.mutation.AddPetIDs(ids...) return _u } // AddPets adds the "pets" edges to the Pet entity. func (_u *UserUpdate) AddPets(v ...*Pet) *UserUpdate { ids := make([]int, len(v)) for i := range v { ids[i] = v[i].ID } return _u.AddPetIDs(ids...) } // AddFriendIDs adds the "friends" edge to the User entity by IDs. func (_u *UserUpdate) AddFriendIDs(ids ...int) *UserUpdate { _u.mutation.AddFriendIDs(ids...) return _u } // AddFriends adds the "friends" edges to the User entity. func (_u *UserUpdate) AddFriends(v ...*User) *UserUpdate { ids := make([]int, len(v)) for i := range v { ids[i] = v[i].ID } return _u.AddFriendIDs(ids...) } // SetBestFriendID sets the "best_friend" edge to the User entity by ID. func (_u *UserUpdate) SetBestFriendID(id int) *UserUpdate { _u.mutation.SetBestFriendID(id) return _u } // SetNillableBestFriendID sets the "best_friend" edge to the User entity by ID if the given value is not nil. func (_u *UserUpdate) SetNillableBestFriendID(id *int) *UserUpdate { if id != nil { _u = _u.SetBestFriendID(*id) } return _u } // SetBestFriend sets the "best_friend" edge to the User entity. func (_u *UserUpdate) SetBestFriend(v *User) *UserUpdate { return _u.SetBestFriendID(v.ID) } // Mutation returns the UserMutation object of the builder. func (_u *UserUpdate) Mutation() *UserMutation { return _u.mutation } // ClearCards clears all "cards" edges to the Card entity. func (_u *UserUpdate) ClearCards() *UserUpdate { _u.mutation.ClearCards() return _u } // RemoveCardIDs removes the "cards" edge to Card entities by IDs. func (_u *UserUpdate) RemoveCardIDs(ids ...int) *UserUpdate { _u.mutation.RemoveCardIDs(ids...) return _u } // RemoveCards removes "cards" edges to Card entities. func (_u *UserUpdate) RemoveCards(v ...*Card) *UserUpdate { ids := make([]int, len(v)) for i := range v { ids[i] = v[i].ID } return _u.RemoveCardIDs(ids...) } // ClearPets clears all "pets" edges to the Pet entity. func (_u *UserUpdate) ClearPets() *UserUpdate { _u.mutation.ClearPets() return _u } // RemovePetIDs removes the "pets" edge to Pet entities by IDs. func (_u *UserUpdate) RemovePetIDs(ids ...int) *UserUpdate { _u.mutation.RemovePetIDs(ids...) return _u } // RemovePets removes "pets" edges to Pet entities. func (_u *UserUpdate) RemovePets(v ...*Pet) *UserUpdate { ids := make([]int, len(v)) for i := range v { ids[i] = v[i].ID } return _u.RemovePetIDs(ids...) } // ClearFriends clears all "friends" edges to the User entity. func (_u *UserUpdate) ClearFriends() *UserUpdate { _u.mutation.ClearFriends() return _u } // RemoveFriendIDs removes the "friends" edge to User entities by IDs. func (_u *UserUpdate) RemoveFriendIDs(ids ...int) *UserUpdate { _u.mutation.RemoveFriendIDs(ids...) return _u } // RemoveFriends removes "friends" edges to User entities. func (_u *UserUpdate) RemoveFriends(v ...*User) *UserUpdate { ids := make([]int, len(v)) for i := range v { ids[i] = v[i].ID } return _u.RemoveFriendIDs(ids...) } // ClearBestFriend clears the "best_friend" edge to the User entity. func (_u *UserUpdate) ClearBestFriend() *UserUpdate { _u.mutation.ClearBestFriend() return _u } // Save executes the query and returns the number of nodes affected by the update operation. func (_u *UserUpdate) Save(ctx context.Context) (int, error) { return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. func (_u *UserUpdate) SaveX(ctx context.Context) int { affected, err := _u.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (_u *UserUpdate) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *UserUpdate) ExecX(ctx context.Context) { if err := _u.Exec(ctx); err != nil { panic(err) } } func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) { _spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt)) 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.Version(); ok { _spec.SetField(user.FieldVersion, field.TypeInt, value) } if value, ok := _u.mutation.AddedVersion(); ok { _spec.AddField(user.FieldVersion, field.TypeInt, value) } if value, ok := _u.mutation.Name(); ok { _spec.SetField(user.FieldName, field.TypeString, value) } if value, ok := _u.mutation.Worth(); ok { _spec.SetField(user.FieldWorth, field.TypeUint, value) } if value, ok := _u.mutation.AddedWorth(); ok { _spec.AddField(user.FieldWorth, field.TypeUint, value) } if _u.mutation.WorthCleared() { _spec.ClearField(user.FieldWorth, field.TypeUint) } if value, ok := _u.mutation.Password(); ok { _spec.SetField(user.FieldPassword, field.TypeString, value) } if _u.mutation.PasswordCleared() { _spec.ClearField(user.FieldPassword, field.TypeString) } if value, ok := _u.mutation.Active(); ok { _spec.SetField(user.FieldActive, field.TypeBool, value) } if _u.mutation.CardsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: user.CardsTable, Columns: []string{user.CardsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(card.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.RemovedCardsIDs(); len(nodes) > 0 && !_u.mutation.CardsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: user.CardsTable, Columns: []string{user.CardsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(card.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.CardsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: user.CardsTable, Columns: []string{user.CardsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(card.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } if _u.mutation.PetsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: user.PetsTable, Columns: []string{user.PetsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(pet.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.RemovedPetsIDs(); len(nodes) > 0 && !_u.mutation.PetsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: user.PetsTable, Columns: []string{user.PetsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(pet.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.PetsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: user.PetsTable, Columns: []string{user.PetsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(pet.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } if _u.mutation.FriendsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, Table: user.FriendsTable, Columns: user.FriendsPrimaryKey, Bidi: true, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.RemovedFriendsIDs(); len(nodes) > 0 && !_u.mutation.FriendsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, Table: user.FriendsTable, Columns: user.FriendsPrimaryKey, Bidi: true, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.FriendsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, Table: user.FriendsTable, Columns: user.FriendsPrimaryKey, Bidi: true, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } if _u.mutation.BestFriendCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2O, Inverse: false, Table: user.BestFriendTable, Columns: []string{user.BestFriendColumn}, Bidi: true, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.BestFriendIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2O, Inverse: false, Table: user.BestFriendTable, Columns: []string{user.BestFriendColumn}, Bidi: true, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt), }, } 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{user.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } _u.mutation.done = true return _node, nil } // UserUpdateOne is the builder for updating a single User entity. type UserUpdateOne struct { config fields []string hooks []Hook mutation *UserMutation } // SetVersion sets the "version" field. func (_u *UserUpdateOne) SetVersion(v int) *UserUpdateOne { _u.mutation.ResetVersion() _u.mutation.SetVersion(v) return _u } // SetNillableVersion sets the "version" field if the given value is not nil. func (_u *UserUpdateOne) SetNillableVersion(v *int) *UserUpdateOne { if v != nil { _u.SetVersion(*v) } return _u } // AddVersion adds value to the "version" field. func (_u *UserUpdateOne) AddVersion(v int) *UserUpdateOne { _u.mutation.AddVersion(v) return _u } // SetName sets the "name" field. func (_u *UserUpdateOne) SetName(v string) *UserUpdateOne { _u.mutation.SetName(v) return _u } // SetNillableName sets the "name" field if the given value is not nil. func (_u *UserUpdateOne) SetNillableName(v *string) *UserUpdateOne { if v != nil { _u.SetName(*v) } return _u } // SetWorth sets the "worth" field. func (_u *UserUpdateOne) SetWorth(v uint) *UserUpdateOne { _u.mutation.ResetWorth() _u.mutation.SetWorth(v) return _u } // SetNillableWorth sets the "worth" field if the given value is not nil. func (_u *UserUpdateOne) SetNillableWorth(v *uint) *UserUpdateOne { if v != nil { _u.SetWorth(*v) } return _u } // AddWorth adds value to the "worth" field. func (_u *UserUpdateOne) AddWorth(v int) *UserUpdateOne { _u.mutation.AddWorth(v) return _u } // ClearWorth clears the value of the "worth" field. func (_u *UserUpdateOne) ClearWorth() *UserUpdateOne { _u.mutation.ClearWorth() return _u } // SetPassword sets the "password" field. func (_u *UserUpdateOne) SetPassword(v string) *UserUpdateOne { _u.mutation.SetPassword(v) return _u } // SetNillablePassword sets the "password" field if the given value is not nil. func (_u *UserUpdateOne) SetNillablePassword(v *string) *UserUpdateOne { if v != nil { _u.SetPassword(*v) } return _u } // ClearPassword clears the value of the "password" field. func (_u *UserUpdateOne) ClearPassword() *UserUpdateOne { _u.mutation.ClearPassword() return _u } // SetActive sets the "active" field. func (_u *UserUpdateOne) SetActive(v bool) *UserUpdateOne { _u.mutation.SetActive(v) return _u } // SetNillableActive sets the "active" field if the given value is not nil. func (_u *UserUpdateOne) SetNillableActive(v *bool) *UserUpdateOne { if v != nil { _u.SetActive(*v) } return _u } // AddCardIDs adds the "cards" edge to the Card entity by IDs. func (_u *UserUpdateOne) AddCardIDs(ids ...int) *UserUpdateOne { _u.mutation.AddCardIDs(ids...) return _u } // AddCards adds the "cards" edges to the Card entity. func (_u *UserUpdateOne) AddCards(v ...*Card) *UserUpdateOne { ids := make([]int, len(v)) for i := range v { ids[i] = v[i].ID } return _u.AddCardIDs(ids...) } // AddPetIDs adds the "pets" edge to the Pet entity by IDs. func (_u *UserUpdateOne) AddPetIDs(ids ...int) *UserUpdateOne { _u.mutation.AddPetIDs(ids...) return _u } // AddPets adds the "pets" edges to the Pet entity. func (_u *UserUpdateOne) AddPets(v ...*Pet) *UserUpdateOne { ids := make([]int, len(v)) for i := range v { ids[i] = v[i].ID } return _u.AddPetIDs(ids...) } // AddFriendIDs adds the "friends" edge to the User entity by IDs. func (_u *UserUpdateOne) AddFriendIDs(ids ...int) *UserUpdateOne { _u.mutation.AddFriendIDs(ids...) return _u } // AddFriends adds the "friends" edges to the User entity. func (_u *UserUpdateOne) AddFriends(v ...*User) *UserUpdateOne { ids := make([]int, len(v)) for i := range v { ids[i] = v[i].ID } return _u.AddFriendIDs(ids...) } // SetBestFriendID sets the "best_friend" edge to the User entity by ID. func (_u *UserUpdateOne) SetBestFriendID(id int) *UserUpdateOne { _u.mutation.SetBestFriendID(id) return _u } // SetNillableBestFriendID sets the "best_friend" edge to the User entity by ID if the given value is not nil. func (_u *UserUpdateOne) SetNillableBestFriendID(id *int) *UserUpdateOne { if id != nil { _u = _u.SetBestFriendID(*id) } return _u } // SetBestFriend sets the "best_friend" edge to the User entity. func (_u *UserUpdateOne) SetBestFriend(v *User) *UserUpdateOne { return _u.SetBestFriendID(v.ID) } // Mutation returns the UserMutation object of the builder. func (_u *UserUpdateOne) Mutation() *UserMutation { return _u.mutation } // ClearCards clears all "cards" edges to the Card entity. func (_u *UserUpdateOne) ClearCards() *UserUpdateOne { _u.mutation.ClearCards() return _u } // RemoveCardIDs removes the "cards" edge to Card entities by IDs. func (_u *UserUpdateOne) RemoveCardIDs(ids ...int) *UserUpdateOne { _u.mutation.RemoveCardIDs(ids...) return _u } // RemoveCards removes "cards" edges to Card entities. func (_u *UserUpdateOne) RemoveCards(v ...*Card) *UserUpdateOne { ids := make([]int, len(v)) for i := range v { ids[i] = v[i].ID } return _u.RemoveCardIDs(ids...) } // ClearPets clears all "pets" edges to the Pet entity. func (_u *UserUpdateOne) ClearPets() *UserUpdateOne { _u.mutation.ClearPets() return _u } // RemovePetIDs removes the "pets" edge to Pet entities by IDs. func (_u *UserUpdateOne) RemovePetIDs(ids ...int) *UserUpdateOne { _u.mutation.RemovePetIDs(ids...) return _u } // RemovePets removes "pets" edges to Pet entities. func (_u *UserUpdateOne) RemovePets(v ...*Pet) *UserUpdateOne { ids := make([]int, len(v)) for i := range v { ids[i] = v[i].ID } return _u.RemovePetIDs(ids...) } // ClearFriends clears all "friends" edges to the User entity. func (_u *UserUpdateOne) ClearFriends() *UserUpdateOne { _u.mutation.ClearFriends() return _u } // RemoveFriendIDs removes the "friends" edge to User entities by IDs. func (_u *UserUpdateOne) RemoveFriendIDs(ids ...int) *UserUpdateOne { _u.mutation.RemoveFriendIDs(ids...) return _u } // RemoveFriends removes "friends" edges to User entities. func (_u *UserUpdateOne) RemoveFriends(v ...*User) *UserUpdateOne { ids := make([]int, len(v)) for i := range v { ids[i] = v[i].ID } return _u.RemoveFriendIDs(ids...) } // ClearBestFriend clears the "best_friend" edge to the User entity. func (_u *UserUpdateOne) ClearBestFriend() *UserUpdateOne { _u.mutation.ClearBestFriend() return _u } // Where appends a list predicates to the UserUpdate builder. func (_u *UserUpdateOne) Where(ps ...predicate.User) *UserUpdateOne { _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 *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne { _u.fields = append([]string{field}, fields...) return _u } // Save executes the query and returns the updated User entity. func (_u *UserUpdateOne) Save(ctx context.Context) (*User, error) { return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. func (_u *UserUpdateOne) SaveX(ctx context.Context) *User { node, err := _u.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (_u *UserUpdateOne) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *UserUpdateOne) ExecX(ctx context.Context) { if err := _u.Exec(ctx); err != nil { panic(err) } } func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) { _spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt)) id, ok := _u.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "User.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, user.FieldID) for _, f := range fields { if !user.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != user.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.Version(); ok { _spec.SetField(user.FieldVersion, field.TypeInt, value) } if value, ok := _u.mutation.AddedVersion(); ok { _spec.AddField(user.FieldVersion, field.TypeInt, value) } if value, ok := _u.mutation.Name(); ok { _spec.SetField(user.FieldName, field.TypeString, value) } if value, ok := _u.mutation.Worth(); ok { _spec.SetField(user.FieldWorth, field.TypeUint, value) } if value, ok := _u.mutation.AddedWorth(); ok { _spec.AddField(user.FieldWorth, field.TypeUint, value) } if _u.mutation.WorthCleared() { _spec.ClearField(user.FieldWorth, field.TypeUint) } if value, ok := _u.mutation.Password(); ok { _spec.SetField(user.FieldPassword, field.TypeString, value) } if _u.mutation.PasswordCleared() { _spec.ClearField(user.FieldPassword, field.TypeString) } if value, ok := _u.mutation.Active(); ok { _spec.SetField(user.FieldActive, field.TypeBool, value) } if _u.mutation.CardsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: user.CardsTable, Columns: []string{user.CardsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(card.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.RemovedCardsIDs(); len(nodes) > 0 && !_u.mutation.CardsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: user.CardsTable, Columns: []string{user.CardsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(card.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.CardsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: user.CardsTable, Columns: []string{user.CardsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(card.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } if _u.mutation.PetsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: user.PetsTable, Columns: []string{user.PetsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(pet.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.RemovedPetsIDs(); len(nodes) > 0 && !_u.mutation.PetsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: user.PetsTable, Columns: []string{user.PetsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(pet.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.PetsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: user.PetsTable, Columns: []string{user.PetsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(pet.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } if _u.mutation.FriendsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, Table: user.FriendsTable, Columns: user.FriendsPrimaryKey, Bidi: true, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.RemovedFriendsIDs(); len(nodes) > 0 && !_u.mutation.FriendsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, Table: user.FriendsTable, Columns: user.FriendsPrimaryKey, Bidi: true, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.FriendsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, Table: user.FriendsTable, Columns: user.FriendsPrimaryKey, Bidi: true, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } if _u.mutation.BestFriendCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2O, Inverse: false, Table: user.BestFriendTable, Columns: []string{user.BestFriendColumn}, Bidi: true, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.BestFriendIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2O, Inverse: false, Table: user.BestFriendTable, Columns: []string{user.BestFriendColumn}, Bidi: true, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } _node = &User{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{user.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } _u.mutation.done = true return _node, nil }