1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519 |
- // Code generated by entc, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "code.osinet.fr/fgm/go__ent_demo/ent/car"
- "code.osinet.fr/fgm/go__ent_demo/ent/group"
- "code.osinet.fr/fgm/go__ent_demo/ent/predicate"
- "code.osinet.fr/fgm/go__ent_demo/ent/user"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "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 (uu *UserUpdate) Where(ps ...predicate.User) *UserUpdate {
- uu.mutation.Where(ps...)
- return uu
- }
- // SetAge sets the "age" field.
- func (uu *UserUpdate) SetAge(i int) *UserUpdate {
- uu.mutation.ResetAge()
- uu.mutation.SetAge(i)
- return uu
- }
- // AddAge adds i to the "age" field.
- func (uu *UserUpdate) AddAge(i int) *UserUpdate {
- uu.mutation.AddAge(i)
- return uu
- }
- // SetName sets the "name" field.
- func (uu *UserUpdate) SetName(s string) *UserUpdate {
- uu.mutation.SetName(s)
- return uu
- }
- // SetNillableName sets the "name" field if the given value is not nil.
- func (uu *UserUpdate) SetNillableName(s *string) *UserUpdate {
- if s != nil {
- uu.SetName(*s)
- }
- return uu
- }
- // SetPassword sets the "password" field.
- func (uu *UserUpdate) SetPassword(s string) *UserUpdate {
- uu.mutation.SetPassword(s)
- return uu
- }
- // SetNillablePassword sets the "password" field if the given value is not nil.
- func (uu *UserUpdate) SetNillablePassword(s *string) *UserUpdate {
- if s != nil {
- uu.SetPassword(*s)
- }
- return uu
- }
- // ClearPassword clears the value of the "password" field.
- func (uu *UserUpdate) ClearPassword() *UserUpdate {
- uu.mutation.ClearPassword()
- return uu
- }
- // SetSize sets the "size" field.
- func (uu *UserUpdate) SetSize(u user.Size) *UserUpdate {
- uu.mutation.SetSize(u)
- return uu
- }
- // SetNillableSize sets the "size" field if the given value is not nil.
- func (uu *UserUpdate) SetNillableSize(u *user.Size) *UserUpdate {
- if u != nil {
- uu.SetSize(*u)
- }
- return uu
- }
- // SetSpouseID sets the "spouse_id" field.
- func (uu *UserUpdate) SetSpouseID(i int) *UserUpdate {
- uu.mutation.SetSpouseID(i)
- return uu
- }
- // SetNillableSpouseID sets the "spouse_id" field if the given value is not nil.
- func (uu *UserUpdate) SetNillableSpouseID(i *int) *UserUpdate {
- if i != nil {
- uu.SetSpouseID(*i)
- }
- return uu
- }
- // ClearSpouseID clears the value of the "spouse_id" field.
- func (uu *UserUpdate) ClearSpouseID() *UserUpdate {
- uu.mutation.ClearSpouseID()
- return uu
- }
- // AddCarIDs adds the "cars" edge to the Car entity by IDs.
- func (uu *UserUpdate) AddCarIDs(ids ...int) *UserUpdate {
- uu.mutation.AddCarIDs(ids...)
- return uu
- }
- // AddCars adds the "cars" edges to the Car entity.
- func (uu *UserUpdate) AddCars(c ...*Car) *UserUpdate {
- ids := make([]int, len(c))
- for i := range c {
- ids[i] = c[i].ID
- }
- return uu.AddCarIDs(ids...)
- }
- // AddGroupIDs adds the "groups" edge to the Group entity by IDs.
- func (uu *UserUpdate) AddGroupIDs(ids ...int) *UserUpdate {
- uu.mutation.AddGroupIDs(ids...)
- return uu
- }
- // AddGroups adds the "groups" edges to the Group entity.
- func (uu *UserUpdate) AddGroups(g ...*Group) *UserUpdate {
- ids := make([]int, len(g))
- for i := range g {
- ids[i] = g[i].ID
- }
- return uu.AddGroupIDs(ids...)
- }
- // SetSpouse sets the "spouse" edge to the User entity.
- func (uu *UserUpdate) SetSpouse(u *User) *UserUpdate {
- return uu.SetSpouseID(u.ID)
- }
- // AddFollowerIDs adds the "followers" edge to the User entity by IDs.
- func (uu *UserUpdate) AddFollowerIDs(ids ...int) *UserUpdate {
- uu.mutation.AddFollowerIDs(ids...)
- return uu
- }
- // AddFollowers adds the "followers" edges to the User entity.
- func (uu *UserUpdate) AddFollowers(u ...*User) *UserUpdate {
- ids := make([]int, len(u))
- for i := range u {
- ids[i] = u[i].ID
- }
- return uu.AddFollowerIDs(ids...)
- }
- // AddFollowingIDs adds the "following" edge to the User entity by IDs.
- func (uu *UserUpdate) AddFollowingIDs(ids ...int) *UserUpdate {
- uu.mutation.AddFollowingIDs(ids...)
- return uu
- }
- // AddFollowing adds the "following" edges to the User entity.
- func (uu *UserUpdate) AddFollowing(u ...*User) *UserUpdate {
- ids := make([]int, len(u))
- for i := range u {
- ids[i] = u[i].ID
- }
- return uu.AddFollowingIDs(ids...)
- }
- // AddFriendIDs adds the "friends" edge to the User entity by IDs.
- func (uu *UserUpdate) AddFriendIDs(ids ...int) *UserUpdate {
- uu.mutation.AddFriendIDs(ids...)
- return uu
- }
- // AddFriends adds the "friends" edges to the User entity.
- func (uu *UserUpdate) AddFriends(u ...*User) *UserUpdate {
- ids := make([]int, len(u))
- for i := range u {
- ids[i] = u[i].ID
- }
- return uu.AddFriendIDs(ids...)
- }
- // Mutation returns the UserMutation object of the builder.
- func (uu *UserUpdate) Mutation() *UserMutation {
- return uu.mutation
- }
- // ClearCars clears all "cars" edges to the Car entity.
- func (uu *UserUpdate) ClearCars() *UserUpdate {
- uu.mutation.ClearCars()
- return uu
- }
- // RemoveCarIDs removes the "cars" edge to Car entities by IDs.
- func (uu *UserUpdate) RemoveCarIDs(ids ...int) *UserUpdate {
- uu.mutation.RemoveCarIDs(ids...)
- return uu
- }
- // RemoveCars removes "cars" edges to Car entities.
- func (uu *UserUpdate) RemoveCars(c ...*Car) *UserUpdate {
- ids := make([]int, len(c))
- for i := range c {
- ids[i] = c[i].ID
- }
- return uu.RemoveCarIDs(ids...)
- }
- // ClearGroups clears all "groups" edges to the Group entity.
- func (uu *UserUpdate) ClearGroups() *UserUpdate {
- uu.mutation.ClearGroups()
- return uu
- }
- // RemoveGroupIDs removes the "groups" edge to Group entities by IDs.
- func (uu *UserUpdate) RemoveGroupIDs(ids ...int) *UserUpdate {
- uu.mutation.RemoveGroupIDs(ids...)
- return uu
- }
- // RemoveGroups removes "groups" edges to Group entities.
- func (uu *UserUpdate) RemoveGroups(g ...*Group) *UserUpdate {
- ids := make([]int, len(g))
- for i := range g {
- ids[i] = g[i].ID
- }
- return uu.RemoveGroupIDs(ids...)
- }
- // ClearSpouse clears the "spouse" edge to the User entity.
- func (uu *UserUpdate) ClearSpouse() *UserUpdate {
- uu.mutation.ClearSpouse()
- return uu
- }
- // ClearFollowers clears all "followers" edges to the User entity.
- func (uu *UserUpdate) ClearFollowers() *UserUpdate {
- uu.mutation.ClearFollowers()
- return uu
- }
- // RemoveFollowerIDs removes the "followers" edge to User entities by IDs.
- func (uu *UserUpdate) RemoveFollowerIDs(ids ...int) *UserUpdate {
- uu.mutation.RemoveFollowerIDs(ids...)
- return uu
- }
- // RemoveFollowers removes "followers" edges to User entities.
- func (uu *UserUpdate) RemoveFollowers(u ...*User) *UserUpdate {
- ids := make([]int, len(u))
- for i := range u {
- ids[i] = u[i].ID
- }
- return uu.RemoveFollowerIDs(ids...)
- }
- // ClearFollowing clears all "following" edges to the User entity.
- func (uu *UserUpdate) ClearFollowing() *UserUpdate {
- uu.mutation.ClearFollowing()
- return uu
- }
- // RemoveFollowingIDs removes the "following" edge to User entities by IDs.
- func (uu *UserUpdate) RemoveFollowingIDs(ids ...int) *UserUpdate {
- uu.mutation.RemoveFollowingIDs(ids...)
- return uu
- }
- // RemoveFollowing removes "following" edges to User entities.
- func (uu *UserUpdate) RemoveFollowing(u ...*User) *UserUpdate {
- ids := make([]int, len(u))
- for i := range u {
- ids[i] = u[i].ID
- }
- return uu.RemoveFollowingIDs(ids...)
- }
- // ClearFriends clears all "friends" edges to the User entity.
- func (uu *UserUpdate) ClearFriends() *UserUpdate {
- uu.mutation.ClearFriends()
- return uu
- }
- // RemoveFriendIDs removes the "friends" edge to User entities by IDs.
- func (uu *UserUpdate) RemoveFriendIDs(ids ...int) *UserUpdate {
- uu.mutation.RemoveFriendIDs(ids...)
- return uu
- }
- // RemoveFriends removes "friends" edges to User entities.
- func (uu *UserUpdate) RemoveFriends(u ...*User) *UserUpdate {
- ids := make([]int, len(u))
- for i := range u {
- ids[i] = u[i].ID
- }
- return uu.RemoveFriendIDs(ids...)
- }
- // Save executes the query and returns the number of nodes affected by the update operation.
- func (uu *UserUpdate) Save(ctx context.Context) (int, error) {
- var (
- err error
- affected int
- )
- if len(uu.hooks) == 0 {
- if err = uu.check(); err != nil {
- return 0, err
- }
- affected, err = uu.sqlSave(ctx)
- } else {
- var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
- mutation, ok := m.(*UserMutation)
- if !ok {
- return nil, fmt.Errorf("unexpected mutation type %T", m)
- }
- if err = uu.check(); err != nil {
- return 0, err
- }
- uu.mutation = mutation
- affected, err = uu.sqlSave(ctx)
- mutation.done = true
- return affected, err
- })
- for i := len(uu.hooks) - 1; i >= 0; i-- {
- if uu.hooks[i] == nil {
- return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
- }
- mut = uu.hooks[i](mut)
- }
- if _, err := mut.Mutate(ctx, uu.mutation); err != nil {
- return 0, err
- }
- }
- return affected, err
- }
- // SaveX is like Save, but panics if an error occurs.
- func (uu *UserUpdate) SaveX(ctx context.Context) int {
- affected, err := uu.Save(ctx)
- if err != nil {
- panic(err)
- }
- return affected
- }
- // Exec executes the query.
- func (uu *UserUpdate) Exec(ctx context.Context) error {
- _, err := uu.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (uu *UserUpdate) ExecX(ctx context.Context) {
- if err := uu.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (uu *UserUpdate) check() error {
- if v, ok := uu.mutation.Age(); ok {
- if err := user.AgeValidator(v); err != nil {
- return &ValidationError{Name: "age", err: fmt.Errorf(`ent: validator failed for field "User.age": %w`, err)}
- }
- }
- if v, ok := uu.mutation.Size(); ok {
- if err := user.SizeValidator(v); err != nil {
- return &ValidationError{Name: "size", err: fmt.Errorf(`ent: validator failed for field "User.size": %w`, err)}
- }
- }
- return nil
- }
- func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
- _spec := &sqlgraph.UpdateSpec{
- Node: &sqlgraph.NodeSpec{
- Table: user.Table,
- Columns: user.Columns,
- ID: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: user.FieldID,
- },
- },
- }
- if ps := uu.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := uu.mutation.Age(); ok {
- _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Value: value,
- Column: user.FieldAge,
- })
- }
- if value, ok := uu.mutation.AddedAge(); ok {
- _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Value: value,
- Column: user.FieldAge,
- })
- }
- if value, ok := uu.mutation.Name(); ok {
- _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
- Type: field.TypeString,
- Value: value,
- Column: user.FieldName,
- })
- }
- if value, ok := uu.mutation.Password(); ok {
- _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
- Type: field.TypeString,
- Value: value,
- Column: user.FieldPassword,
- })
- }
- if uu.mutation.PasswordCleared() {
- _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
- Type: field.TypeString,
- Column: user.FieldPassword,
- })
- }
- if value, ok := uu.mutation.Size(); ok {
- _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
- Type: field.TypeEnum,
- Value: value,
- Column: user.FieldSize,
- })
- }
- if uu.mutation.CarsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: user.CarsTable,
- Columns: []string{user.CarsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: car.FieldID,
- },
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := uu.mutation.RemovedCarsIDs(); len(nodes) > 0 && !uu.mutation.CarsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: user.CarsTable,
- Columns: []string{user.CarsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: car.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := uu.mutation.CarsIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: user.CarsTable,
- Columns: []string{user.CarsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: car.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if uu.mutation.GroupsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2M,
- Inverse: true,
- Table: user.GroupsTable,
- Columns: user.GroupsPrimaryKey,
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: group.FieldID,
- },
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := uu.mutation.RemovedGroupsIDs(); len(nodes) > 0 && !uu.mutation.GroupsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2M,
- Inverse: true,
- Table: user.GroupsTable,
- Columns: user.GroupsPrimaryKey,
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: group.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := uu.mutation.GroupsIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2M,
- Inverse: true,
- Table: user.GroupsTable,
- Columns: user.GroupsPrimaryKey,
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: group.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if uu.mutation.SpouseCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2O,
- Inverse: false,
- Table: user.SpouseTable,
- Columns: []string{user.SpouseColumn},
- Bidi: true,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: user.FieldID,
- },
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := uu.mutation.SpouseIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2O,
- Inverse: false,
- Table: user.SpouseTable,
- Columns: []string{user.SpouseColumn},
- Bidi: true,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: user.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if uu.mutation.FollowersCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2M,
- Inverse: true,
- Table: user.FollowersTable,
- Columns: user.FollowersPrimaryKey,
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: user.FieldID,
- },
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := uu.mutation.RemovedFollowersIDs(); len(nodes) > 0 && !uu.mutation.FollowersCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2M,
- Inverse: true,
- Table: user.FollowersTable,
- Columns: user.FollowersPrimaryKey,
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: user.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := uu.mutation.FollowersIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2M,
- Inverse: true,
- Table: user.FollowersTable,
- Columns: user.FollowersPrimaryKey,
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: user.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if uu.mutation.FollowingCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2M,
- Inverse: false,
- Table: user.FollowingTable,
- Columns: user.FollowingPrimaryKey,
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: user.FieldID,
- },
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := uu.mutation.RemovedFollowingIDs(); len(nodes) > 0 && !uu.mutation.FollowingCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2M,
- Inverse: false,
- Table: user.FollowingTable,
- Columns: user.FollowingPrimaryKey,
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: user.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := uu.mutation.FollowingIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2M,
- Inverse: false,
- Table: user.FollowingTable,
- Columns: user.FollowingPrimaryKey,
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: user.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if uu.mutation.FriendsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2M,
- Inverse: false,
- Table: user.FriendsTable,
- Columns: user.FriendsPrimaryKey,
- Bidi: true,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: user.FieldID,
- },
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := uu.mutation.RemovedFriendsIDs(); len(nodes) > 0 && !uu.mutation.FriendsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2M,
- Inverse: false,
- Table: user.FriendsTable,
- Columns: user.FriendsPrimaryKey,
- Bidi: true,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: user.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := uu.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.FieldSpec{
- Type: field.TypeInt,
- Column: user.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if n, err = sqlgraph.UpdateNodes(ctx, uu.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{user.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{err.Error(), err}
- }
- return 0, err
- }
- return n, nil
- }
- // UserUpdateOne is the builder for updating a single User entity.
- type UserUpdateOne struct {
- config
- fields []string
- hooks []Hook
- mutation *UserMutation
- }
- // SetAge sets the "age" field.
- func (uuo *UserUpdateOne) SetAge(i int) *UserUpdateOne {
- uuo.mutation.ResetAge()
- uuo.mutation.SetAge(i)
- return uuo
- }
- // AddAge adds i to the "age" field.
- func (uuo *UserUpdateOne) AddAge(i int) *UserUpdateOne {
- uuo.mutation.AddAge(i)
- return uuo
- }
- // SetName sets the "name" field.
- func (uuo *UserUpdateOne) SetName(s string) *UserUpdateOne {
- uuo.mutation.SetName(s)
- return uuo
- }
- // SetNillableName sets the "name" field if the given value is not nil.
- func (uuo *UserUpdateOne) SetNillableName(s *string) *UserUpdateOne {
- if s != nil {
- uuo.SetName(*s)
- }
- return uuo
- }
- // SetPassword sets the "password" field.
- func (uuo *UserUpdateOne) SetPassword(s string) *UserUpdateOne {
- uuo.mutation.SetPassword(s)
- return uuo
- }
- // SetNillablePassword sets the "password" field if the given value is not nil.
- func (uuo *UserUpdateOne) SetNillablePassword(s *string) *UserUpdateOne {
- if s != nil {
- uuo.SetPassword(*s)
- }
- return uuo
- }
- // ClearPassword clears the value of the "password" field.
- func (uuo *UserUpdateOne) ClearPassword() *UserUpdateOne {
- uuo.mutation.ClearPassword()
- return uuo
- }
- // SetSize sets the "size" field.
- func (uuo *UserUpdateOne) SetSize(u user.Size) *UserUpdateOne {
- uuo.mutation.SetSize(u)
- return uuo
- }
- // SetNillableSize sets the "size" field if the given value is not nil.
- func (uuo *UserUpdateOne) SetNillableSize(u *user.Size) *UserUpdateOne {
- if u != nil {
- uuo.SetSize(*u)
- }
- return uuo
- }
- // SetSpouseID sets the "spouse_id" field.
- func (uuo *UserUpdateOne) SetSpouseID(i int) *UserUpdateOne {
- uuo.mutation.SetSpouseID(i)
- return uuo
- }
- // SetNillableSpouseID sets the "spouse_id" field if the given value is not nil.
- func (uuo *UserUpdateOne) SetNillableSpouseID(i *int) *UserUpdateOne {
- if i != nil {
- uuo.SetSpouseID(*i)
- }
- return uuo
- }
- // ClearSpouseID clears the value of the "spouse_id" field.
- func (uuo *UserUpdateOne) ClearSpouseID() *UserUpdateOne {
- uuo.mutation.ClearSpouseID()
- return uuo
- }
- // AddCarIDs adds the "cars" edge to the Car entity by IDs.
- func (uuo *UserUpdateOne) AddCarIDs(ids ...int) *UserUpdateOne {
- uuo.mutation.AddCarIDs(ids...)
- return uuo
- }
- // AddCars adds the "cars" edges to the Car entity.
- func (uuo *UserUpdateOne) AddCars(c ...*Car) *UserUpdateOne {
- ids := make([]int, len(c))
- for i := range c {
- ids[i] = c[i].ID
- }
- return uuo.AddCarIDs(ids...)
- }
- // AddGroupIDs adds the "groups" edge to the Group entity by IDs.
- func (uuo *UserUpdateOne) AddGroupIDs(ids ...int) *UserUpdateOne {
- uuo.mutation.AddGroupIDs(ids...)
- return uuo
- }
- // AddGroups adds the "groups" edges to the Group entity.
- func (uuo *UserUpdateOne) AddGroups(g ...*Group) *UserUpdateOne {
- ids := make([]int, len(g))
- for i := range g {
- ids[i] = g[i].ID
- }
- return uuo.AddGroupIDs(ids...)
- }
- // SetSpouse sets the "spouse" edge to the User entity.
- func (uuo *UserUpdateOne) SetSpouse(u *User) *UserUpdateOne {
- return uuo.SetSpouseID(u.ID)
- }
- // AddFollowerIDs adds the "followers" edge to the User entity by IDs.
- func (uuo *UserUpdateOne) AddFollowerIDs(ids ...int) *UserUpdateOne {
- uuo.mutation.AddFollowerIDs(ids...)
- return uuo
- }
- // AddFollowers adds the "followers" edges to the User entity.
- func (uuo *UserUpdateOne) AddFollowers(u ...*User) *UserUpdateOne {
- ids := make([]int, len(u))
- for i := range u {
- ids[i] = u[i].ID
- }
- return uuo.AddFollowerIDs(ids...)
- }
- // AddFollowingIDs adds the "following" edge to the User entity by IDs.
- func (uuo *UserUpdateOne) AddFollowingIDs(ids ...int) *UserUpdateOne {
- uuo.mutation.AddFollowingIDs(ids...)
- return uuo
- }
- // AddFollowing adds the "following" edges to the User entity.
- func (uuo *UserUpdateOne) AddFollowing(u ...*User) *UserUpdateOne {
- ids := make([]int, len(u))
- for i := range u {
- ids[i] = u[i].ID
- }
- return uuo.AddFollowingIDs(ids...)
- }
- // AddFriendIDs adds the "friends" edge to the User entity by IDs.
- func (uuo *UserUpdateOne) AddFriendIDs(ids ...int) *UserUpdateOne {
- uuo.mutation.AddFriendIDs(ids...)
- return uuo
- }
- // AddFriends adds the "friends" edges to the User entity.
- func (uuo *UserUpdateOne) AddFriends(u ...*User) *UserUpdateOne {
- ids := make([]int, len(u))
- for i := range u {
- ids[i] = u[i].ID
- }
- return uuo.AddFriendIDs(ids...)
- }
- // Mutation returns the UserMutation object of the builder.
- func (uuo *UserUpdateOne) Mutation() *UserMutation {
- return uuo.mutation
- }
- // ClearCars clears all "cars" edges to the Car entity.
- func (uuo *UserUpdateOne) ClearCars() *UserUpdateOne {
- uuo.mutation.ClearCars()
- return uuo
- }
- // RemoveCarIDs removes the "cars" edge to Car entities by IDs.
- func (uuo *UserUpdateOne) RemoveCarIDs(ids ...int) *UserUpdateOne {
- uuo.mutation.RemoveCarIDs(ids...)
- return uuo
- }
- // RemoveCars removes "cars" edges to Car entities.
- func (uuo *UserUpdateOne) RemoveCars(c ...*Car) *UserUpdateOne {
- ids := make([]int, len(c))
- for i := range c {
- ids[i] = c[i].ID
- }
- return uuo.RemoveCarIDs(ids...)
- }
- // ClearGroups clears all "groups" edges to the Group entity.
- func (uuo *UserUpdateOne) ClearGroups() *UserUpdateOne {
- uuo.mutation.ClearGroups()
- return uuo
- }
- // RemoveGroupIDs removes the "groups" edge to Group entities by IDs.
- func (uuo *UserUpdateOne) RemoveGroupIDs(ids ...int) *UserUpdateOne {
- uuo.mutation.RemoveGroupIDs(ids...)
- return uuo
- }
- // RemoveGroups removes "groups" edges to Group entities.
- func (uuo *UserUpdateOne) RemoveGroups(g ...*Group) *UserUpdateOne {
- ids := make([]int, len(g))
- for i := range g {
- ids[i] = g[i].ID
- }
- return uuo.RemoveGroupIDs(ids...)
- }
- // ClearSpouse clears the "spouse" edge to the User entity.
- func (uuo *UserUpdateOne) ClearSpouse() *UserUpdateOne {
- uuo.mutation.ClearSpouse()
- return uuo
- }
- // ClearFollowers clears all "followers" edges to the User entity.
- func (uuo *UserUpdateOne) ClearFollowers() *UserUpdateOne {
- uuo.mutation.ClearFollowers()
- return uuo
- }
- // RemoveFollowerIDs removes the "followers" edge to User entities by IDs.
- func (uuo *UserUpdateOne) RemoveFollowerIDs(ids ...int) *UserUpdateOne {
- uuo.mutation.RemoveFollowerIDs(ids...)
- return uuo
- }
- // RemoveFollowers removes "followers" edges to User entities.
- func (uuo *UserUpdateOne) RemoveFollowers(u ...*User) *UserUpdateOne {
- ids := make([]int, len(u))
- for i := range u {
- ids[i] = u[i].ID
- }
- return uuo.RemoveFollowerIDs(ids...)
- }
- // ClearFollowing clears all "following" edges to the User entity.
- func (uuo *UserUpdateOne) ClearFollowing() *UserUpdateOne {
- uuo.mutation.ClearFollowing()
- return uuo
- }
- // RemoveFollowingIDs removes the "following" edge to User entities by IDs.
- func (uuo *UserUpdateOne) RemoveFollowingIDs(ids ...int) *UserUpdateOne {
- uuo.mutation.RemoveFollowingIDs(ids...)
- return uuo
- }
- // RemoveFollowing removes "following" edges to User entities.
- func (uuo *UserUpdateOne) RemoveFollowing(u ...*User) *UserUpdateOne {
- ids := make([]int, len(u))
- for i := range u {
- ids[i] = u[i].ID
- }
- return uuo.RemoveFollowingIDs(ids...)
- }
- // ClearFriends clears all "friends" edges to the User entity.
- func (uuo *UserUpdateOne) ClearFriends() *UserUpdateOne {
- uuo.mutation.ClearFriends()
- return uuo
- }
- // RemoveFriendIDs removes the "friends" edge to User entities by IDs.
- func (uuo *UserUpdateOne) RemoveFriendIDs(ids ...int) *UserUpdateOne {
- uuo.mutation.RemoveFriendIDs(ids...)
- return uuo
- }
- // RemoveFriends removes "friends" edges to User entities.
- func (uuo *UserUpdateOne) RemoveFriends(u ...*User) *UserUpdateOne {
- ids := make([]int, len(u))
- for i := range u {
- ids[i] = u[i].ID
- }
- return uuo.RemoveFriendIDs(ids...)
- }
- // Select allows selecting one or more fields (columns) of the returned entity.
- // The default is selecting all fields defined in the entity schema.
- func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne {
- uuo.fields = append([]string{field}, fields...)
- return uuo
- }
- // Save executes the query and returns the updated User entity.
- func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) {
- var (
- err error
- node *User
- )
- if len(uuo.hooks) == 0 {
- if err = uuo.check(); err != nil {
- return nil, err
- }
- node, err = uuo.sqlSave(ctx)
- } else {
- var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
- mutation, ok := m.(*UserMutation)
- if !ok {
- return nil, fmt.Errorf("unexpected mutation type %T", m)
- }
- if err = uuo.check(); err != nil {
- return nil, err
- }
- uuo.mutation = mutation
- node, err = uuo.sqlSave(ctx)
- mutation.done = true
- return node, err
- })
- for i := len(uuo.hooks) - 1; i >= 0; i-- {
- if uuo.hooks[i] == nil {
- return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
- }
- mut = uuo.hooks[i](mut)
- }
- if _, err := mut.Mutate(ctx, uuo.mutation); err != nil {
- return nil, err
- }
- }
- return node, err
- }
- // SaveX is like Save, but panics if an error occurs.
- func (uuo *UserUpdateOne) SaveX(ctx context.Context) *User {
- node, err := uuo.Save(ctx)
- if err != nil {
- panic(err)
- }
- return node
- }
- // Exec executes the query on the entity.
- func (uuo *UserUpdateOne) Exec(ctx context.Context) error {
- _, err := uuo.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (uuo *UserUpdateOne) ExecX(ctx context.Context) {
- if err := uuo.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (uuo *UserUpdateOne) check() error {
- if v, ok := uuo.mutation.Age(); ok {
- if err := user.AgeValidator(v); err != nil {
- return &ValidationError{Name: "age", err: fmt.Errorf(`ent: validator failed for field "User.age": %w`, err)}
- }
- }
- if v, ok := uuo.mutation.Size(); ok {
- if err := user.SizeValidator(v); err != nil {
- return &ValidationError{Name: "size", err: fmt.Errorf(`ent: validator failed for field "User.size": %w`, err)}
- }
- }
- return nil
- }
- func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
- _spec := &sqlgraph.UpdateSpec{
- Node: &sqlgraph.NodeSpec{
- Table: user.Table,
- Columns: user.Columns,
- ID: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: user.FieldID,
- },
- },
- }
- id, ok := uuo.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 := uuo.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 := uuo.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := uuo.mutation.Age(); ok {
- _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Value: value,
- Column: user.FieldAge,
- })
- }
- if value, ok := uuo.mutation.AddedAge(); ok {
- _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Value: value,
- Column: user.FieldAge,
- })
- }
- if value, ok := uuo.mutation.Name(); ok {
- _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
- Type: field.TypeString,
- Value: value,
- Column: user.FieldName,
- })
- }
- if value, ok := uuo.mutation.Password(); ok {
- _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
- Type: field.TypeString,
- Value: value,
- Column: user.FieldPassword,
- })
- }
- if uuo.mutation.PasswordCleared() {
- _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
- Type: field.TypeString,
- Column: user.FieldPassword,
- })
- }
- if value, ok := uuo.mutation.Size(); ok {
- _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
- Type: field.TypeEnum,
- Value: value,
- Column: user.FieldSize,
- })
- }
- if uuo.mutation.CarsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: user.CarsTable,
- Columns: []string{user.CarsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: car.FieldID,
- },
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := uuo.mutation.RemovedCarsIDs(); len(nodes) > 0 && !uuo.mutation.CarsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: user.CarsTable,
- Columns: []string{user.CarsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: car.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := uuo.mutation.CarsIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: user.CarsTable,
- Columns: []string{user.CarsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: car.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if uuo.mutation.GroupsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2M,
- Inverse: true,
- Table: user.GroupsTable,
- Columns: user.GroupsPrimaryKey,
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: group.FieldID,
- },
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := uuo.mutation.RemovedGroupsIDs(); len(nodes) > 0 && !uuo.mutation.GroupsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2M,
- Inverse: true,
- Table: user.GroupsTable,
- Columns: user.GroupsPrimaryKey,
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: group.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := uuo.mutation.GroupsIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2M,
- Inverse: true,
- Table: user.GroupsTable,
- Columns: user.GroupsPrimaryKey,
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: group.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if uuo.mutation.SpouseCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2O,
- Inverse: false,
- Table: user.SpouseTable,
- Columns: []string{user.SpouseColumn},
- Bidi: true,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: user.FieldID,
- },
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := uuo.mutation.SpouseIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2O,
- Inverse: false,
- Table: user.SpouseTable,
- Columns: []string{user.SpouseColumn},
- Bidi: true,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: user.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if uuo.mutation.FollowersCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2M,
- Inverse: true,
- Table: user.FollowersTable,
- Columns: user.FollowersPrimaryKey,
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: user.FieldID,
- },
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := uuo.mutation.RemovedFollowersIDs(); len(nodes) > 0 && !uuo.mutation.FollowersCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2M,
- Inverse: true,
- Table: user.FollowersTable,
- Columns: user.FollowersPrimaryKey,
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: user.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := uuo.mutation.FollowersIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2M,
- Inverse: true,
- Table: user.FollowersTable,
- Columns: user.FollowersPrimaryKey,
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: user.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if uuo.mutation.FollowingCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2M,
- Inverse: false,
- Table: user.FollowingTable,
- Columns: user.FollowingPrimaryKey,
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: user.FieldID,
- },
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := uuo.mutation.RemovedFollowingIDs(); len(nodes) > 0 && !uuo.mutation.FollowingCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2M,
- Inverse: false,
- Table: user.FollowingTable,
- Columns: user.FollowingPrimaryKey,
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: user.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := uuo.mutation.FollowingIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2M,
- Inverse: false,
- Table: user.FollowingTable,
- Columns: user.FollowingPrimaryKey,
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: user.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if uuo.mutation.FriendsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2M,
- Inverse: false,
- Table: user.FriendsTable,
- Columns: user.FriendsPrimaryKey,
- Bidi: true,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: user.FieldID,
- },
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := uuo.mutation.RemovedFriendsIDs(); len(nodes) > 0 && !uuo.mutation.FriendsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2M,
- Inverse: false,
- Table: user.FriendsTable,
- Columns: user.FriendsPrimaryKey,
- Bidi: true,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: user.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := uuo.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.FieldSpec{
- Type: field.TypeInt,
- Column: user.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- _node = &User{config: uuo.config}
- _spec.Assign = _node.assignValues
- _spec.ScanValues = _node.scanValues
- if err = sqlgraph.UpdateNode(ctx, uuo.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{user.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{err.Error(), err}
- }
- return nil, err
- }
- return _node, nil
- }
|