user_update.go 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519
  1. // Code generated by entc, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "code.osinet.fr/fgm/go__ent_demo/ent/car"
  8. "code.osinet.fr/fgm/go__ent_demo/ent/group"
  9. "code.osinet.fr/fgm/go__ent_demo/ent/predicate"
  10. "code.osinet.fr/fgm/go__ent_demo/ent/user"
  11. "entgo.io/ent/dialect/sql"
  12. "entgo.io/ent/dialect/sql/sqlgraph"
  13. "entgo.io/ent/schema/field"
  14. )
  15. // UserUpdate is the builder for updating User entities.
  16. type UserUpdate struct {
  17. config
  18. hooks []Hook
  19. mutation *UserMutation
  20. }
  21. // Where appends a list predicates to the UserUpdate builder.
  22. func (uu *UserUpdate) Where(ps ...predicate.User) *UserUpdate {
  23. uu.mutation.Where(ps...)
  24. return uu
  25. }
  26. // SetAge sets the "age" field.
  27. func (uu *UserUpdate) SetAge(i int) *UserUpdate {
  28. uu.mutation.ResetAge()
  29. uu.mutation.SetAge(i)
  30. return uu
  31. }
  32. // AddAge adds i to the "age" field.
  33. func (uu *UserUpdate) AddAge(i int) *UserUpdate {
  34. uu.mutation.AddAge(i)
  35. return uu
  36. }
  37. // SetName sets the "name" field.
  38. func (uu *UserUpdate) SetName(s string) *UserUpdate {
  39. uu.mutation.SetName(s)
  40. return uu
  41. }
  42. // SetNillableName sets the "name" field if the given value is not nil.
  43. func (uu *UserUpdate) SetNillableName(s *string) *UserUpdate {
  44. if s != nil {
  45. uu.SetName(*s)
  46. }
  47. return uu
  48. }
  49. // SetPassword sets the "password" field.
  50. func (uu *UserUpdate) SetPassword(s string) *UserUpdate {
  51. uu.mutation.SetPassword(s)
  52. return uu
  53. }
  54. // SetNillablePassword sets the "password" field if the given value is not nil.
  55. func (uu *UserUpdate) SetNillablePassword(s *string) *UserUpdate {
  56. if s != nil {
  57. uu.SetPassword(*s)
  58. }
  59. return uu
  60. }
  61. // ClearPassword clears the value of the "password" field.
  62. func (uu *UserUpdate) ClearPassword() *UserUpdate {
  63. uu.mutation.ClearPassword()
  64. return uu
  65. }
  66. // SetSize sets the "size" field.
  67. func (uu *UserUpdate) SetSize(u user.Size) *UserUpdate {
  68. uu.mutation.SetSize(u)
  69. return uu
  70. }
  71. // SetNillableSize sets the "size" field if the given value is not nil.
  72. func (uu *UserUpdate) SetNillableSize(u *user.Size) *UserUpdate {
  73. if u != nil {
  74. uu.SetSize(*u)
  75. }
  76. return uu
  77. }
  78. // SetSpouseID sets the "spouse_id" field.
  79. func (uu *UserUpdate) SetSpouseID(i int) *UserUpdate {
  80. uu.mutation.SetSpouseID(i)
  81. return uu
  82. }
  83. // SetNillableSpouseID sets the "spouse_id" field if the given value is not nil.
  84. func (uu *UserUpdate) SetNillableSpouseID(i *int) *UserUpdate {
  85. if i != nil {
  86. uu.SetSpouseID(*i)
  87. }
  88. return uu
  89. }
  90. // ClearSpouseID clears the value of the "spouse_id" field.
  91. func (uu *UserUpdate) ClearSpouseID() *UserUpdate {
  92. uu.mutation.ClearSpouseID()
  93. return uu
  94. }
  95. // AddCarIDs adds the "cars" edge to the Car entity by IDs.
  96. func (uu *UserUpdate) AddCarIDs(ids ...int) *UserUpdate {
  97. uu.mutation.AddCarIDs(ids...)
  98. return uu
  99. }
  100. // AddCars adds the "cars" edges to the Car entity.
  101. func (uu *UserUpdate) AddCars(c ...*Car) *UserUpdate {
  102. ids := make([]int, len(c))
  103. for i := range c {
  104. ids[i] = c[i].ID
  105. }
  106. return uu.AddCarIDs(ids...)
  107. }
  108. // AddGroupIDs adds the "groups" edge to the Group entity by IDs.
  109. func (uu *UserUpdate) AddGroupIDs(ids ...int) *UserUpdate {
  110. uu.mutation.AddGroupIDs(ids...)
  111. return uu
  112. }
  113. // AddGroups adds the "groups" edges to the Group entity.
  114. func (uu *UserUpdate) AddGroups(g ...*Group) *UserUpdate {
  115. ids := make([]int, len(g))
  116. for i := range g {
  117. ids[i] = g[i].ID
  118. }
  119. return uu.AddGroupIDs(ids...)
  120. }
  121. // SetSpouse sets the "spouse" edge to the User entity.
  122. func (uu *UserUpdate) SetSpouse(u *User) *UserUpdate {
  123. return uu.SetSpouseID(u.ID)
  124. }
  125. // AddFollowerIDs adds the "followers" edge to the User entity by IDs.
  126. func (uu *UserUpdate) AddFollowerIDs(ids ...int) *UserUpdate {
  127. uu.mutation.AddFollowerIDs(ids...)
  128. return uu
  129. }
  130. // AddFollowers adds the "followers" edges to the User entity.
  131. func (uu *UserUpdate) AddFollowers(u ...*User) *UserUpdate {
  132. ids := make([]int, len(u))
  133. for i := range u {
  134. ids[i] = u[i].ID
  135. }
  136. return uu.AddFollowerIDs(ids...)
  137. }
  138. // AddFollowingIDs adds the "following" edge to the User entity by IDs.
  139. func (uu *UserUpdate) AddFollowingIDs(ids ...int) *UserUpdate {
  140. uu.mutation.AddFollowingIDs(ids...)
  141. return uu
  142. }
  143. // AddFollowing adds the "following" edges to the User entity.
  144. func (uu *UserUpdate) AddFollowing(u ...*User) *UserUpdate {
  145. ids := make([]int, len(u))
  146. for i := range u {
  147. ids[i] = u[i].ID
  148. }
  149. return uu.AddFollowingIDs(ids...)
  150. }
  151. // AddFriendIDs adds the "friends" edge to the User entity by IDs.
  152. func (uu *UserUpdate) AddFriendIDs(ids ...int) *UserUpdate {
  153. uu.mutation.AddFriendIDs(ids...)
  154. return uu
  155. }
  156. // AddFriends adds the "friends" edges to the User entity.
  157. func (uu *UserUpdate) AddFriends(u ...*User) *UserUpdate {
  158. ids := make([]int, len(u))
  159. for i := range u {
  160. ids[i] = u[i].ID
  161. }
  162. return uu.AddFriendIDs(ids...)
  163. }
  164. // Mutation returns the UserMutation object of the builder.
  165. func (uu *UserUpdate) Mutation() *UserMutation {
  166. return uu.mutation
  167. }
  168. // ClearCars clears all "cars" edges to the Car entity.
  169. func (uu *UserUpdate) ClearCars() *UserUpdate {
  170. uu.mutation.ClearCars()
  171. return uu
  172. }
  173. // RemoveCarIDs removes the "cars" edge to Car entities by IDs.
  174. func (uu *UserUpdate) RemoveCarIDs(ids ...int) *UserUpdate {
  175. uu.mutation.RemoveCarIDs(ids...)
  176. return uu
  177. }
  178. // RemoveCars removes "cars" edges to Car entities.
  179. func (uu *UserUpdate) RemoveCars(c ...*Car) *UserUpdate {
  180. ids := make([]int, len(c))
  181. for i := range c {
  182. ids[i] = c[i].ID
  183. }
  184. return uu.RemoveCarIDs(ids...)
  185. }
  186. // ClearGroups clears all "groups" edges to the Group entity.
  187. func (uu *UserUpdate) ClearGroups() *UserUpdate {
  188. uu.mutation.ClearGroups()
  189. return uu
  190. }
  191. // RemoveGroupIDs removes the "groups" edge to Group entities by IDs.
  192. func (uu *UserUpdate) RemoveGroupIDs(ids ...int) *UserUpdate {
  193. uu.mutation.RemoveGroupIDs(ids...)
  194. return uu
  195. }
  196. // RemoveGroups removes "groups" edges to Group entities.
  197. func (uu *UserUpdate) RemoveGroups(g ...*Group) *UserUpdate {
  198. ids := make([]int, len(g))
  199. for i := range g {
  200. ids[i] = g[i].ID
  201. }
  202. return uu.RemoveGroupIDs(ids...)
  203. }
  204. // ClearSpouse clears the "spouse" edge to the User entity.
  205. func (uu *UserUpdate) ClearSpouse() *UserUpdate {
  206. uu.mutation.ClearSpouse()
  207. return uu
  208. }
  209. // ClearFollowers clears all "followers" edges to the User entity.
  210. func (uu *UserUpdate) ClearFollowers() *UserUpdate {
  211. uu.mutation.ClearFollowers()
  212. return uu
  213. }
  214. // RemoveFollowerIDs removes the "followers" edge to User entities by IDs.
  215. func (uu *UserUpdate) RemoveFollowerIDs(ids ...int) *UserUpdate {
  216. uu.mutation.RemoveFollowerIDs(ids...)
  217. return uu
  218. }
  219. // RemoveFollowers removes "followers" edges to User entities.
  220. func (uu *UserUpdate) RemoveFollowers(u ...*User) *UserUpdate {
  221. ids := make([]int, len(u))
  222. for i := range u {
  223. ids[i] = u[i].ID
  224. }
  225. return uu.RemoveFollowerIDs(ids...)
  226. }
  227. // ClearFollowing clears all "following" edges to the User entity.
  228. func (uu *UserUpdate) ClearFollowing() *UserUpdate {
  229. uu.mutation.ClearFollowing()
  230. return uu
  231. }
  232. // RemoveFollowingIDs removes the "following" edge to User entities by IDs.
  233. func (uu *UserUpdate) RemoveFollowingIDs(ids ...int) *UserUpdate {
  234. uu.mutation.RemoveFollowingIDs(ids...)
  235. return uu
  236. }
  237. // RemoveFollowing removes "following" edges to User entities.
  238. func (uu *UserUpdate) RemoveFollowing(u ...*User) *UserUpdate {
  239. ids := make([]int, len(u))
  240. for i := range u {
  241. ids[i] = u[i].ID
  242. }
  243. return uu.RemoveFollowingIDs(ids...)
  244. }
  245. // ClearFriends clears all "friends" edges to the User entity.
  246. func (uu *UserUpdate) ClearFriends() *UserUpdate {
  247. uu.mutation.ClearFriends()
  248. return uu
  249. }
  250. // RemoveFriendIDs removes the "friends" edge to User entities by IDs.
  251. func (uu *UserUpdate) RemoveFriendIDs(ids ...int) *UserUpdate {
  252. uu.mutation.RemoveFriendIDs(ids...)
  253. return uu
  254. }
  255. // RemoveFriends removes "friends" edges to User entities.
  256. func (uu *UserUpdate) RemoveFriends(u ...*User) *UserUpdate {
  257. ids := make([]int, len(u))
  258. for i := range u {
  259. ids[i] = u[i].ID
  260. }
  261. return uu.RemoveFriendIDs(ids...)
  262. }
  263. // Save executes the query and returns the number of nodes affected by the update operation.
  264. func (uu *UserUpdate) Save(ctx context.Context) (int, error) {
  265. var (
  266. err error
  267. affected int
  268. )
  269. if len(uu.hooks) == 0 {
  270. if err = uu.check(); err != nil {
  271. return 0, err
  272. }
  273. affected, err = uu.sqlSave(ctx)
  274. } else {
  275. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  276. mutation, ok := m.(*UserMutation)
  277. if !ok {
  278. return nil, fmt.Errorf("unexpected mutation type %T", m)
  279. }
  280. if err = uu.check(); err != nil {
  281. return 0, err
  282. }
  283. uu.mutation = mutation
  284. affected, err = uu.sqlSave(ctx)
  285. mutation.done = true
  286. return affected, err
  287. })
  288. for i := len(uu.hooks) - 1; i >= 0; i-- {
  289. if uu.hooks[i] == nil {
  290. return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
  291. }
  292. mut = uu.hooks[i](mut)
  293. }
  294. if _, err := mut.Mutate(ctx, uu.mutation); err != nil {
  295. return 0, err
  296. }
  297. }
  298. return affected, err
  299. }
  300. // SaveX is like Save, but panics if an error occurs.
  301. func (uu *UserUpdate) SaveX(ctx context.Context) int {
  302. affected, err := uu.Save(ctx)
  303. if err != nil {
  304. panic(err)
  305. }
  306. return affected
  307. }
  308. // Exec executes the query.
  309. func (uu *UserUpdate) Exec(ctx context.Context) error {
  310. _, err := uu.Save(ctx)
  311. return err
  312. }
  313. // ExecX is like Exec, but panics if an error occurs.
  314. func (uu *UserUpdate) ExecX(ctx context.Context) {
  315. if err := uu.Exec(ctx); err != nil {
  316. panic(err)
  317. }
  318. }
  319. // check runs all checks and user-defined validators on the builder.
  320. func (uu *UserUpdate) check() error {
  321. if v, ok := uu.mutation.Age(); ok {
  322. if err := user.AgeValidator(v); err != nil {
  323. return &ValidationError{Name: "age", err: fmt.Errorf(`ent: validator failed for field "User.age": %w`, err)}
  324. }
  325. }
  326. if v, ok := uu.mutation.Size(); ok {
  327. if err := user.SizeValidator(v); err != nil {
  328. return &ValidationError{Name: "size", err: fmt.Errorf(`ent: validator failed for field "User.size": %w`, err)}
  329. }
  330. }
  331. return nil
  332. }
  333. func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
  334. _spec := &sqlgraph.UpdateSpec{
  335. Node: &sqlgraph.NodeSpec{
  336. Table: user.Table,
  337. Columns: user.Columns,
  338. ID: &sqlgraph.FieldSpec{
  339. Type: field.TypeInt,
  340. Column: user.FieldID,
  341. },
  342. },
  343. }
  344. if ps := uu.mutation.predicates; len(ps) > 0 {
  345. _spec.Predicate = func(selector *sql.Selector) {
  346. for i := range ps {
  347. ps[i](selector)
  348. }
  349. }
  350. }
  351. if value, ok := uu.mutation.Age(); ok {
  352. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  353. Type: field.TypeInt,
  354. Value: value,
  355. Column: user.FieldAge,
  356. })
  357. }
  358. if value, ok := uu.mutation.AddedAge(); ok {
  359. _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
  360. Type: field.TypeInt,
  361. Value: value,
  362. Column: user.FieldAge,
  363. })
  364. }
  365. if value, ok := uu.mutation.Name(); ok {
  366. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  367. Type: field.TypeString,
  368. Value: value,
  369. Column: user.FieldName,
  370. })
  371. }
  372. if value, ok := uu.mutation.Password(); ok {
  373. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  374. Type: field.TypeString,
  375. Value: value,
  376. Column: user.FieldPassword,
  377. })
  378. }
  379. if uu.mutation.PasswordCleared() {
  380. _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
  381. Type: field.TypeString,
  382. Column: user.FieldPassword,
  383. })
  384. }
  385. if value, ok := uu.mutation.Size(); ok {
  386. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  387. Type: field.TypeEnum,
  388. Value: value,
  389. Column: user.FieldSize,
  390. })
  391. }
  392. if uu.mutation.CarsCleared() {
  393. edge := &sqlgraph.EdgeSpec{
  394. Rel: sqlgraph.O2M,
  395. Inverse: false,
  396. Table: user.CarsTable,
  397. Columns: []string{user.CarsColumn},
  398. Bidi: false,
  399. Target: &sqlgraph.EdgeTarget{
  400. IDSpec: &sqlgraph.FieldSpec{
  401. Type: field.TypeInt,
  402. Column: car.FieldID,
  403. },
  404. },
  405. }
  406. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  407. }
  408. if nodes := uu.mutation.RemovedCarsIDs(); len(nodes) > 0 && !uu.mutation.CarsCleared() {
  409. edge := &sqlgraph.EdgeSpec{
  410. Rel: sqlgraph.O2M,
  411. Inverse: false,
  412. Table: user.CarsTable,
  413. Columns: []string{user.CarsColumn},
  414. Bidi: false,
  415. Target: &sqlgraph.EdgeTarget{
  416. IDSpec: &sqlgraph.FieldSpec{
  417. Type: field.TypeInt,
  418. Column: car.FieldID,
  419. },
  420. },
  421. }
  422. for _, k := range nodes {
  423. edge.Target.Nodes = append(edge.Target.Nodes, k)
  424. }
  425. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  426. }
  427. if nodes := uu.mutation.CarsIDs(); len(nodes) > 0 {
  428. edge := &sqlgraph.EdgeSpec{
  429. Rel: sqlgraph.O2M,
  430. Inverse: false,
  431. Table: user.CarsTable,
  432. Columns: []string{user.CarsColumn},
  433. Bidi: false,
  434. Target: &sqlgraph.EdgeTarget{
  435. IDSpec: &sqlgraph.FieldSpec{
  436. Type: field.TypeInt,
  437. Column: car.FieldID,
  438. },
  439. },
  440. }
  441. for _, k := range nodes {
  442. edge.Target.Nodes = append(edge.Target.Nodes, k)
  443. }
  444. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  445. }
  446. if uu.mutation.GroupsCleared() {
  447. edge := &sqlgraph.EdgeSpec{
  448. Rel: sqlgraph.M2M,
  449. Inverse: true,
  450. Table: user.GroupsTable,
  451. Columns: user.GroupsPrimaryKey,
  452. Bidi: false,
  453. Target: &sqlgraph.EdgeTarget{
  454. IDSpec: &sqlgraph.FieldSpec{
  455. Type: field.TypeInt,
  456. Column: group.FieldID,
  457. },
  458. },
  459. }
  460. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  461. }
  462. if nodes := uu.mutation.RemovedGroupsIDs(); len(nodes) > 0 && !uu.mutation.GroupsCleared() {
  463. edge := &sqlgraph.EdgeSpec{
  464. Rel: sqlgraph.M2M,
  465. Inverse: true,
  466. Table: user.GroupsTable,
  467. Columns: user.GroupsPrimaryKey,
  468. Bidi: false,
  469. Target: &sqlgraph.EdgeTarget{
  470. IDSpec: &sqlgraph.FieldSpec{
  471. Type: field.TypeInt,
  472. Column: group.FieldID,
  473. },
  474. },
  475. }
  476. for _, k := range nodes {
  477. edge.Target.Nodes = append(edge.Target.Nodes, k)
  478. }
  479. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  480. }
  481. if nodes := uu.mutation.GroupsIDs(); len(nodes) > 0 {
  482. edge := &sqlgraph.EdgeSpec{
  483. Rel: sqlgraph.M2M,
  484. Inverse: true,
  485. Table: user.GroupsTable,
  486. Columns: user.GroupsPrimaryKey,
  487. Bidi: false,
  488. Target: &sqlgraph.EdgeTarget{
  489. IDSpec: &sqlgraph.FieldSpec{
  490. Type: field.TypeInt,
  491. Column: group.FieldID,
  492. },
  493. },
  494. }
  495. for _, k := range nodes {
  496. edge.Target.Nodes = append(edge.Target.Nodes, k)
  497. }
  498. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  499. }
  500. if uu.mutation.SpouseCleared() {
  501. edge := &sqlgraph.EdgeSpec{
  502. Rel: sqlgraph.O2O,
  503. Inverse: false,
  504. Table: user.SpouseTable,
  505. Columns: []string{user.SpouseColumn},
  506. Bidi: true,
  507. Target: &sqlgraph.EdgeTarget{
  508. IDSpec: &sqlgraph.FieldSpec{
  509. Type: field.TypeInt,
  510. Column: user.FieldID,
  511. },
  512. },
  513. }
  514. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  515. }
  516. if nodes := uu.mutation.SpouseIDs(); len(nodes) > 0 {
  517. edge := &sqlgraph.EdgeSpec{
  518. Rel: sqlgraph.O2O,
  519. Inverse: false,
  520. Table: user.SpouseTable,
  521. Columns: []string{user.SpouseColumn},
  522. Bidi: true,
  523. Target: &sqlgraph.EdgeTarget{
  524. IDSpec: &sqlgraph.FieldSpec{
  525. Type: field.TypeInt,
  526. Column: user.FieldID,
  527. },
  528. },
  529. }
  530. for _, k := range nodes {
  531. edge.Target.Nodes = append(edge.Target.Nodes, k)
  532. }
  533. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  534. }
  535. if uu.mutation.FollowersCleared() {
  536. edge := &sqlgraph.EdgeSpec{
  537. Rel: sqlgraph.M2M,
  538. Inverse: true,
  539. Table: user.FollowersTable,
  540. Columns: user.FollowersPrimaryKey,
  541. Bidi: false,
  542. Target: &sqlgraph.EdgeTarget{
  543. IDSpec: &sqlgraph.FieldSpec{
  544. Type: field.TypeInt,
  545. Column: user.FieldID,
  546. },
  547. },
  548. }
  549. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  550. }
  551. if nodes := uu.mutation.RemovedFollowersIDs(); len(nodes) > 0 && !uu.mutation.FollowersCleared() {
  552. edge := &sqlgraph.EdgeSpec{
  553. Rel: sqlgraph.M2M,
  554. Inverse: true,
  555. Table: user.FollowersTable,
  556. Columns: user.FollowersPrimaryKey,
  557. Bidi: false,
  558. Target: &sqlgraph.EdgeTarget{
  559. IDSpec: &sqlgraph.FieldSpec{
  560. Type: field.TypeInt,
  561. Column: user.FieldID,
  562. },
  563. },
  564. }
  565. for _, k := range nodes {
  566. edge.Target.Nodes = append(edge.Target.Nodes, k)
  567. }
  568. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  569. }
  570. if nodes := uu.mutation.FollowersIDs(); len(nodes) > 0 {
  571. edge := &sqlgraph.EdgeSpec{
  572. Rel: sqlgraph.M2M,
  573. Inverse: true,
  574. Table: user.FollowersTable,
  575. Columns: user.FollowersPrimaryKey,
  576. Bidi: false,
  577. Target: &sqlgraph.EdgeTarget{
  578. IDSpec: &sqlgraph.FieldSpec{
  579. Type: field.TypeInt,
  580. Column: user.FieldID,
  581. },
  582. },
  583. }
  584. for _, k := range nodes {
  585. edge.Target.Nodes = append(edge.Target.Nodes, k)
  586. }
  587. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  588. }
  589. if uu.mutation.FollowingCleared() {
  590. edge := &sqlgraph.EdgeSpec{
  591. Rel: sqlgraph.M2M,
  592. Inverse: false,
  593. Table: user.FollowingTable,
  594. Columns: user.FollowingPrimaryKey,
  595. Bidi: false,
  596. Target: &sqlgraph.EdgeTarget{
  597. IDSpec: &sqlgraph.FieldSpec{
  598. Type: field.TypeInt,
  599. Column: user.FieldID,
  600. },
  601. },
  602. }
  603. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  604. }
  605. if nodes := uu.mutation.RemovedFollowingIDs(); len(nodes) > 0 && !uu.mutation.FollowingCleared() {
  606. edge := &sqlgraph.EdgeSpec{
  607. Rel: sqlgraph.M2M,
  608. Inverse: false,
  609. Table: user.FollowingTable,
  610. Columns: user.FollowingPrimaryKey,
  611. Bidi: false,
  612. Target: &sqlgraph.EdgeTarget{
  613. IDSpec: &sqlgraph.FieldSpec{
  614. Type: field.TypeInt,
  615. Column: user.FieldID,
  616. },
  617. },
  618. }
  619. for _, k := range nodes {
  620. edge.Target.Nodes = append(edge.Target.Nodes, k)
  621. }
  622. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  623. }
  624. if nodes := uu.mutation.FollowingIDs(); len(nodes) > 0 {
  625. edge := &sqlgraph.EdgeSpec{
  626. Rel: sqlgraph.M2M,
  627. Inverse: false,
  628. Table: user.FollowingTable,
  629. Columns: user.FollowingPrimaryKey,
  630. Bidi: false,
  631. Target: &sqlgraph.EdgeTarget{
  632. IDSpec: &sqlgraph.FieldSpec{
  633. Type: field.TypeInt,
  634. Column: user.FieldID,
  635. },
  636. },
  637. }
  638. for _, k := range nodes {
  639. edge.Target.Nodes = append(edge.Target.Nodes, k)
  640. }
  641. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  642. }
  643. if uu.mutation.FriendsCleared() {
  644. edge := &sqlgraph.EdgeSpec{
  645. Rel: sqlgraph.M2M,
  646. Inverse: false,
  647. Table: user.FriendsTable,
  648. Columns: user.FriendsPrimaryKey,
  649. Bidi: true,
  650. Target: &sqlgraph.EdgeTarget{
  651. IDSpec: &sqlgraph.FieldSpec{
  652. Type: field.TypeInt,
  653. Column: user.FieldID,
  654. },
  655. },
  656. }
  657. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  658. }
  659. if nodes := uu.mutation.RemovedFriendsIDs(); len(nodes) > 0 && !uu.mutation.FriendsCleared() {
  660. edge := &sqlgraph.EdgeSpec{
  661. Rel: sqlgraph.M2M,
  662. Inverse: false,
  663. Table: user.FriendsTable,
  664. Columns: user.FriendsPrimaryKey,
  665. Bidi: true,
  666. Target: &sqlgraph.EdgeTarget{
  667. IDSpec: &sqlgraph.FieldSpec{
  668. Type: field.TypeInt,
  669. Column: user.FieldID,
  670. },
  671. },
  672. }
  673. for _, k := range nodes {
  674. edge.Target.Nodes = append(edge.Target.Nodes, k)
  675. }
  676. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  677. }
  678. if nodes := uu.mutation.FriendsIDs(); len(nodes) > 0 {
  679. edge := &sqlgraph.EdgeSpec{
  680. Rel: sqlgraph.M2M,
  681. Inverse: false,
  682. Table: user.FriendsTable,
  683. Columns: user.FriendsPrimaryKey,
  684. Bidi: true,
  685. Target: &sqlgraph.EdgeTarget{
  686. IDSpec: &sqlgraph.FieldSpec{
  687. Type: field.TypeInt,
  688. Column: user.FieldID,
  689. },
  690. },
  691. }
  692. for _, k := range nodes {
  693. edge.Target.Nodes = append(edge.Target.Nodes, k)
  694. }
  695. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  696. }
  697. if n, err = sqlgraph.UpdateNodes(ctx, uu.driver, _spec); err != nil {
  698. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  699. err = &NotFoundError{user.Label}
  700. } else if sqlgraph.IsConstraintError(err) {
  701. err = &ConstraintError{err.Error(), err}
  702. }
  703. return 0, err
  704. }
  705. return n, nil
  706. }
  707. // UserUpdateOne is the builder for updating a single User entity.
  708. type UserUpdateOne struct {
  709. config
  710. fields []string
  711. hooks []Hook
  712. mutation *UserMutation
  713. }
  714. // SetAge sets the "age" field.
  715. func (uuo *UserUpdateOne) SetAge(i int) *UserUpdateOne {
  716. uuo.mutation.ResetAge()
  717. uuo.mutation.SetAge(i)
  718. return uuo
  719. }
  720. // AddAge adds i to the "age" field.
  721. func (uuo *UserUpdateOne) AddAge(i int) *UserUpdateOne {
  722. uuo.mutation.AddAge(i)
  723. return uuo
  724. }
  725. // SetName sets the "name" field.
  726. func (uuo *UserUpdateOne) SetName(s string) *UserUpdateOne {
  727. uuo.mutation.SetName(s)
  728. return uuo
  729. }
  730. // SetNillableName sets the "name" field if the given value is not nil.
  731. func (uuo *UserUpdateOne) SetNillableName(s *string) *UserUpdateOne {
  732. if s != nil {
  733. uuo.SetName(*s)
  734. }
  735. return uuo
  736. }
  737. // SetPassword sets the "password" field.
  738. func (uuo *UserUpdateOne) SetPassword(s string) *UserUpdateOne {
  739. uuo.mutation.SetPassword(s)
  740. return uuo
  741. }
  742. // SetNillablePassword sets the "password" field if the given value is not nil.
  743. func (uuo *UserUpdateOne) SetNillablePassword(s *string) *UserUpdateOne {
  744. if s != nil {
  745. uuo.SetPassword(*s)
  746. }
  747. return uuo
  748. }
  749. // ClearPassword clears the value of the "password" field.
  750. func (uuo *UserUpdateOne) ClearPassword() *UserUpdateOne {
  751. uuo.mutation.ClearPassword()
  752. return uuo
  753. }
  754. // SetSize sets the "size" field.
  755. func (uuo *UserUpdateOne) SetSize(u user.Size) *UserUpdateOne {
  756. uuo.mutation.SetSize(u)
  757. return uuo
  758. }
  759. // SetNillableSize sets the "size" field if the given value is not nil.
  760. func (uuo *UserUpdateOne) SetNillableSize(u *user.Size) *UserUpdateOne {
  761. if u != nil {
  762. uuo.SetSize(*u)
  763. }
  764. return uuo
  765. }
  766. // SetSpouseID sets the "spouse_id" field.
  767. func (uuo *UserUpdateOne) SetSpouseID(i int) *UserUpdateOne {
  768. uuo.mutation.SetSpouseID(i)
  769. return uuo
  770. }
  771. // SetNillableSpouseID sets the "spouse_id" field if the given value is not nil.
  772. func (uuo *UserUpdateOne) SetNillableSpouseID(i *int) *UserUpdateOne {
  773. if i != nil {
  774. uuo.SetSpouseID(*i)
  775. }
  776. return uuo
  777. }
  778. // ClearSpouseID clears the value of the "spouse_id" field.
  779. func (uuo *UserUpdateOne) ClearSpouseID() *UserUpdateOne {
  780. uuo.mutation.ClearSpouseID()
  781. return uuo
  782. }
  783. // AddCarIDs adds the "cars" edge to the Car entity by IDs.
  784. func (uuo *UserUpdateOne) AddCarIDs(ids ...int) *UserUpdateOne {
  785. uuo.mutation.AddCarIDs(ids...)
  786. return uuo
  787. }
  788. // AddCars adds the "cars" edges to the Car entity.
  789. func (uuo *UserUpdateOne) AddCars(c ...*Car) *UserUpdateOne {
  790. ids := make([]int, len(c))
  791. for i := range c {
  792. ids[i] = c[i].ID
  793. }
  794. return uuo.AddCarIDs(ids...)
  795. }
  796. // AddGroupIDs adds the "groups" edge to the Group entity by IDs.
  797. func (uuo *UserUpdateOne) AddGroupIDs(ids ...int) *UserUpdateOne {
  798. uuo.mutation.AddGroupIDs(ids...)
  799. return uuo
  800. }
  801. // AddGroups adds the "groups" edges to the Group entity.
  802. func (uuo *UserUpdateOne) AddGroups(g ...*Group) *UserUpdateOne {
  803. ids := make([]int, len(g))
  804. for i := range g {
  805. ids[i] = g[i].ID
  806. }
  807. return uuo.AddGroupIDs(ids...)
  808. }
  809. // SetSpouse sets the "spouse" edge to the User entity.
  810. func (uuo *UserUpdateOne) SetSpouse(u *User) *UserUpdateOne {
  811. return uuo.SetSpouseID(u.ID)
  812. }
  813. // AddFollowerIDs adds the "followers" edge to the User entity by IDs.
  814. func (uuo *UserUpdateOne) AddFollowerIDs(ids ...int) *UserUpdateOne {
  815. uuo.mutation.AddFollowerIDs(ids...)
  816. return uuo
  817. }
  818. // AddFollowers adds the "followers" edges to the User entity.
  819. func (uuo *UserUpdateOne) AddFollowers(u ...*User) *UserUpdateOne {
  820. ids := make([]int, len(u))
  821. for i := range u {
  822. ids[i] = u[i].ID
  823. }
  824. return uuo.AddFollowerIDs(ids...)
  825. }
  826. // AddFollowingIDs adds the "following" edge to the User entity by IDs.
  827. func (uuo *UserUpdateOne) AddFollowingIDs(ids ...int) *UserUpdateOne {
  828. uuo.mutation.AddFollowingIDs(ids...)
  829. return uuo
  830. }
  831. // AddFollowing adds the "following" edges to the User entity.
  832. func (uuo *UserUpdateOne) AddFollowing(u ...*User) *UserUpdateOne {
  833. ids := make([]int, len(u))
  834. for i := range u {
  835. ids[i] = u[i].ID
  836. }
  837. return uuo.AddFollowingIDs(ids...)
  838. }
  839. // AddFriendIDs adds the "friends" edge to the User entity by IDs.
  840. func (uuo *UserUpdateOne) AddFriendIDs(ids ...int) *UserUpdateOne {
  841. uuo.mutation.AddFriendIDs(ids...)
  842. return uuo
  843. }
  844. // AddFriends adds the "friends" edges to the User entity.
  845. func (uuo *UserUpdateOne) AddFriends(u ...*User) *UserUpdateOne {
  846. ids := make([]int, len(u))
  847. for i := range u {
  848. ids[i] = u[i].ID
  849. }
  850. return uuo.AddFriendIDs(ids...)
  851. }
  852. // Mutation returns the UserMutation object of the builder.
  853. func (uuo *UserUpdateOne) Mutation() *UserMutation {
  854. return uuo.mutation
  855. }
  856. // ClearCars clears all "cars" edges to the Car entity.
  857. func (uuo *UserUpdateOne) ClearCars() *UserUpdateOne {
  858. uuo.mutation.ClearCars()
  859. return uuo
  860. }
  861. // RemoveCarIDs removes the "cars" edge to Car entities by IDs.
  862. func (uuo *UserUpdateOne) RemoveCarIDs(ids ...int) *UserUpdateOne {
  863. uuo.mutation.RemoveCarIDs(ids...)
  864. return uuo
  865. }
  866. // RemoveCars removes "cars" edges to Car entities.
  867. func (uuo *UserUpdateOne) RemoveCars(c ...*Car) *UserUpdateOne {
  868. ids := make([]int, len(c))
  869. for i := range c {
  870. ids[i] = c[i].ID
  871. }
  872. return uuo.RemoveCarIDs(ids...)
  873. }
  874. // ClearGroups clears all "groups" edges to the Group entity.
  875. func (uuo *UserUpdateOne) ClearGroups() *UserUpdateOne {
  876. uuo.mutation.ClearGroups()
  877. return uuo
  878. }
  879. // RemoveGroupIDs removes the "groups" edge to Group entities by IDs.
  880. func (uuo *UserUpdateOne) RemoveGroupIDs(ids ...int) *UserUpdateOne {
  881. uuo.mutation.RemoveGroupIDs(ids...)
  882. return uuo
  883. }
  884. // RemoveGroups removes "groups" edges to Group entities.
  885. func (uuo *UserUpdateOne) RemoveGroups(g ...*Group) *UserUpdateOne {
  886. ids := make([]int, len(g))
  887. for i := range g {
  888. ids[i] = g[i].ID
  889. }
  890. return uuo.RemoveGroupIDs(ids...)
  891. }
  892. // ClearSpouse clears the "spouse" edge to the User entity.
  893. func (uuo *UserUpdateOne) ClearSpouse() *UserUpdateOne {
  894. uuo.mutation.ClearSpouse()
  895. return uuo
  896. }
  897. // ClearFollowers clears all "followers" edges to the User entity.
  898. func (uuo *UserUpdateOne) ClearFollowers() *UserUpdateOne {
  899. uuo.mutation.ClearFollowers()
  900. return uuo
  901. }
  902. // RemoveFollowerIDs removes the "followers" edge to User entities by IDs.
  903. func (uuo *UserUpdateOne) RemoveFollowerIDs(ids ...int) *UserUpdateOne {
  904. uuo.mutation.RemoveFollowerIDs(ids...)
  905. return uuo
  906. }
  907. // RemoveFollowers removes "followers" edges to User entities.
  908. func (uuo *UserUpdateOne) RemoveFollowers(u ...*User) *UserUpdateOne {
  909. ids := make([]int, len(u))
  910. for i := range u {
  911. ids[i] = u[i].ID
  912. }
  913. return uuo.RemoveFollowerIDs(ids...)
  914. }
  915. // ClearFollowing clears all "following" edges to the User entity.
  916. func (uuo *UserUpdateOne) ClearFollowing() *UserUpdateOne {
  917. uuo.mutation.ClearFollowing()
  918. return uuo
  919. }
  920. // RemoveFollowingIDs removes the "following" edge to User entities by IDs.
  921. func (uuo *UserUpdateOne) RemoveFollowingIDs(ids ...int) *UserUpdateOne {
  922. uuo.mutation.RemoveFollowingIDs(ids...)
  923. return uuo
  924. }
  925. // RemoveFollowing removes "following" edges to User entities.
  926. func (uuo *UserUpdateOne) RemoveFollowing(u ...*User) *UserUpdateOne {
  927. ids := make([]int, len(u))
  928. for i := range u {
  929. ids[i] = u[i].ID
  930. }
  931. return uuo.RemoveFollowingIDs(ids...)
  932. }
  933. // ClearFriends clears all "friends" edges to the User entity.
  934. func (uuo *UserUpdateOne) ClearFriends() *UserUpdateOne {
  935. uuo.mutation.ClearFriends()
  936. return uuo
  937. }
  938. // RemoveFriendIDs removes the "friends" edge to User entities by IDs.
  939. func (uuo *UserUpdateOne) RemoveFriendIDs(ids ...int) *UserUpdateOne {
  940. uuo.mutation.RemoveFriendIDs(ids...)
  941. return uuo
  942. }
  943. // RemoveFriends removes "friends" edges to User entities.
  944. func (uuo *UserUpdateOne) RemoveFriends(u ...*User) *UserUpdateOne {
  945. ids := make([]int, len(u))
  946. for i := range u {
  947. ids[i] = u[i].ID
  948. }
  949. return uuo.RemoveFriendIDs(ids...)
  950. }
  951. // Select allows selecting one or more fields (columns) of the returned entity.
  952. // The default is selecting all fields defined in the entity schema.
  953. func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne {
  954. uuo.fields = append([]string{field}, fields...)
  955. return uuo
  956. }
  957. // Save executes the query and returns the updated User entity.
  958. func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) {
  959. var (
  960. err error
  961. node *User
  962. )
  963. if len(uuo.hooks) == 0 {
  964. if err = uuo.check(); err != nil {
  965. return nil, err
  966. }
  967. node, err = uuo.sqlSave(ctx)
  968. } else {
  969. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  970. mutation, ok := m.(*UserMutation)
  971. if !ok {
  972. return nil, fmt.Errorf("unexpected mutation type %T", m)
  973. }
  974. if err = uuo.check(); err != nil {
  975. return nil, err
  976. }
  977. uuo.mutation = mutation
  978. node, err = uuo.sqlSave(ctx)
  979. mutation.done = true
  980. return node, err
  981. })
  982. for i := len(uuo.hooks) - 1; i >= 0; i-- {
  983. if uuo.hooks[i] == nil {
  984. return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
  985. }
  986. mut = uuo.hooks[i](mut)
  987. }
  988. if _, err := mut.Mutate(ctx, uuo.mutation); err != nil {
  989. return nil, err
  990. }
  991. }
  992. return node, err
  993. }
  994. // SaveX is like Save, but panics if an error occurs.
  995. func (uuo *UserUpdateOne) SaveX(ctx context.Context) *User {
  996. node, err := uuo.Save(ctx)
  997. if err != nil {
  998. panic(err)
  999. }
  1000. return node
  1001. }
  1002. // Exec executes the query on the entity.
  1003. func (uuo *UserUpdateOne) Exec(ctx context.Context) error {
  1004. _, err := uuo.Save(ctx)
  1005. return err
  1006. }
  1007. // ExecX is like Exec, but panics if an error occurs.
  1008. func (uuo *UserUpdateOne) ExecX(ctx context.Context) {
  1009. if err := uuo.Exec(ctx); err != nil {
  1010. panic(err)
  1011. }
  1012. }
  1013. // check runs all checks and user-defined validators on the builder.
  1014. func (uuo *UserUpdateOne) check() error {
  1015. if v, ok := uuo.mutation.Age(); ok {
  1016. if err := user.AgeValidator(v); err != nil {
  1017. return &ValidationError{Name: "age", err: fmt.Errorf(`ent: validator failed for field "User.age": %w`, err)}
  1018. }
  1019. }
  1020. if v, ok := uuo.mutation.Size(); ok {
  1021. if err := user.SizeValidator(v); err != nil {
  1022. return &ValidationError{Name: "size", err: fmt.Errorf(`ent: validator failed for field "User.size": %w`, err)}
  1023. }
  1024. }
  1025. return nil
  1026. }
  1027. func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
  1028. _spec := &sqlgraph.UpdateSpec{
  1029. Node: &sqlgraph.NodeSpec{
  1030. Table: user.Table,
  1031. Columns: user.Columns,
  1032. ID: &sqlgraph.FieldSpec{
  1033. Type: field.TypeInt,
  1034. Column: user.FieldID,
  1035. },
  1036. },
  1037. }
  1038. id, ok := uuo.mutation.ID()
  1039. if !ok {
  1040. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "User.id" for update`)}
  1041. }
  1042. _spec.Node.ID.Value = id
  1043. if fields := uuo.fields; len(fields) > 0 {
  1044. _spec.Node.Columns = make([]string, 0, len(fields))
  1045. _spec.Node.Columns = append(_spec.Node.Columns, user.FieldID)
  1046. for _, f := range fields {
  1047. if !user.ValidColumn(f) {
  1048. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  1049. }
  1050. if f != user.FieldID {
  1051. _spec.Node.Columns = append(_spec.Node.Columns, f)
  1052. }
  1053. }
  1054. }
  1055. if ps := uuo.mutation.predicates; len(ps) > 0 {
  1056. _spec.Predicate = func(selector *sql.Selector) {
  1057. for i := range ps {
  1058. ps[i](selector)
  1059. }
  1060. }
  1061. }
  1062. if value, ok := uuo.mutation.Age(); ok {
  1063. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  1064. Type: field.TypeInt,
  1065. Value: value,
  1066. Column: user.FieldAge,
  1067. })
  1068. }
  1069. if value, ok := uuo.mutation.AddedAge(); ok {
  1070. _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
  1071. Type: field.TypeInt,
  1072. Value: value,
  1073. Column: user.FieldAge,
  1074. })
  1075. }
  1076. if value, ok := uuo.mutation.Name(); ok {
  1077. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  1078. Type: field.TypeString,
  1079. Value: value,
  1080. Column: user.FieldName,
  1081. })
  1082. }
  1083. if value, ok := uuo.mutation.Password(); ok {
  1084. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  1085. Type: field.TypeString,
  1086. Value: value,
  1087. Column: user.FieldPassword,
  1088. })
  1089. }
  1090. if uuo.mutation.PasswordCleared() {
  1091. _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
  1092. Type: field.TypeString,
  1093. Column: user.FieldPassword,
  1094. })
  1095. }
  1096. if value, ok := uuo.mutation.Size(); ok {
  1097. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  1098. Type: field.TypeEnum,
  1099. Value: value,
  1100. Column: user.FieldSize,
  1101. })
  1102. }
  1103. if uuo.mutation.CarsCleared() {
  1104. edge := &sqlgraph.EdgeSpec{
  1105. Rel: sqlgraph.O2M,
  1106. Inverse: false,
  1107. Table: user.CarsTable,
  1108. Columns: []string{user.CarsColumn},
  1109. Bidi: false,
  1110. Target: &sqlgraph.EdgeTarget{
  1111. IDSpec: &sqlgraph.FieldSpec{
  1112. Type: field.TypeInt,
  1113. Column: car.FieldID,
  1114. },
  1115. },
  1116. }
  1117. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1118. }
  1119. if nodes := uuo.mutation.RemovedCarsIDs(); len(nodes) > 0 && !uuo.mutation.CarsCleared() {
  1120. edge := &sqlgraph.EdgeSpec{
  1121. Rel: sqlgraph.O2M,
  1122. Inverse: false,
  1123. Table: user.CarsTable,
  1124. Columns: []string{user.CarsColumn},
  1125. Bidi: false,
  1126. Target: &sqlgraph.EdgeTarget{
  1127. IDSpec: &sqlgraph.FieldSpec{
  1128. Type: field.TypeInt,
  1129. Column: car.FieldID,
  1130. },
  1131. },
  1132. }
  1133. for _, k := range nodes {
  1134. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1135. }
  1136. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1137. }
  1138. if nodes := uuo.mutation.CarsIDs(); len(nodes) > 0 {
  1139. edge := &sqlgraph.EdgeSpec{
  1140. Rel: sqlgraph.O2M,
  1141. Inverse: false,
  1142. Table: user.CarsTable,
  1143. Columns: []string{user.CarsColumn},
  1144. Bidi: false,
  1145. Target: &sqlgraph.EdgeTarget{
  1146. IDSpec: &sqlgraph.FieldSpec{
  1147. Type: field.TypeInt,
  1148. Column: car.FieldID,
  1149. },
  1150. },
  1151. }
  1152. for _, k := range nodes {
  1153. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1154. }
  1155. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1156. }
  1157. if uuo.mutation.GroupsCleared() {
  1158. edge := &sqlgraph.EdgeSpec{
  1159. Rel: sqlgraph.M2M,
  1160. Inverse: true,
  1161. Table: user.GroupsTable,
  1162. Columns: user.GroupsPrimaryKey,
  1163. Bidi: false,
  1164. Target: &sqlgraph.EdgeTarget{
  1165. IDSpec: &sqlgraph.FieldSpec{
  1166. Type: field.TypeInt,
  1167. Column: group.FieldID,
  1168. },
  1169. },
  1170. }
  1171. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1172. }
  1173. if nodes := uuo.mutation.RemovedGroupsIDs(); len(nodes) > 0 && !uuo.mutation.GroupsCleared() {
  1174. edge := &sqlgraph.EdgeSpec{
  1175. Rel: sqlgraph.M2M,
  1176. Inverse: true,
  1177. Table: user.GroupsTable,
  1178. Columns: user.GroupsPrimaryKey,
  1179. Bidi: false,
  1180. Target: &sqlgraph.EdgeTarget{
  1181. IDSpec: &sqlgraph.FieldSpec{
  1182. Type: field.TypeInt,
  1183. Column: group.FieldID,
  1184. },
  1185. },
  1186. }
  1187. for _, k := range nodes {
  1188. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1189. }
  1190. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1191. }
  1192. if nodes := uuo.mutation.GroupsIDs(); len(nodes) > 0 {
  1193. edge := &sqlgraph.EdgeSpec{
  1194. Rel: sqlgraph.M2M,
  1195. Inverse: true,
  1196. Table: user.GroupsTable,
  1197. Columns: user.GroupsPrimaryKey,
  1198. Bidi: false,
  1199. Target: &sqlgraph.EdgeTarget{
  1200. IDSpec: &sqlgraph.FieldSpec{
  1201. Type: field.TypeInt,
  1202. Column: group.FieldID,
  1203. },
  1204. },
  1205. }
  1206. for _, k := range nodes {
  1207. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1208. }
  1209. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1210. }
  1211. if uuo.mutation.SpouseCleared() {
  1212. edge := &sqlgraph.EdgeSpec{
  1213. Rel: sqlgraph.O2O,
  1214. Inverse: false,
  1215. Table: user.SpouseTable,
  1216. Columns: []string{user.SpouseColumn},
  1217. Bidi: true,
  1218. Target: &sqlgraph.EdgeTarget{
  1219. IDSpec: &sqlgraph.FieldSpec{
  1220. Type: field.TypeInt,
  1221. Column: user.FieldID,
  1222. },
  1223. },
  1224. }
  1225. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1226. }
  1227. if nodes := uuo.mutation.SpouseIDs(); len(nodes) > 0 {
  1228. edge := &sqlgraph.EdgeSpec{
  1229. Rel: sqlgraph.O2O,
  1230. Inverse: false,
  1231. Table: user.SpouseTable,
  1232. Columns: []string{user.SpouseColumn},
  1233. Bidi: true,
  1234. Target: &sqlgraph.EdgeTarget{
  1235. IDSpec: &sqlgraph.FieldSpec{
  1236. Type: field.TypeInt,
  1237. Column: user.FieldID,
  1238. },
  1239. },
  1240. }
  1241. for _, k := range nodes {
  1242. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1243. }
  1244. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1245. }
  1246. if uuo.mutation.FollowersCleared() {
  1247. edge := &sqlgraph.EdgeSpec{
  1248. Rel: sqlgraph.M2M,
  1249. Inverse: true,
  1250. Table: user.FollowersTable,
  1251. Columns: user.FollowersPrimaryKey,
  1252. Bidi: false,
  1253. Target: &sqlgraph.EdgeTarget{
  1254. IDSpec: &sqlgraph.FieldSpec{
  1255. Type: field.TypeInt,
  1256. Column: user.FieldID,
  1257. },
  1258. },
  1259. }
  1260. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1261. }
  1262. if nodes := uuo.mutation.RemovedFollowersIDs(); len(nodes) > 0 && !uuo.mutation.FollowersCleared() {
  1263. edge := &sqlgraph.EdgeSpec{
  1264. Rel: sqlgraph.M2M,
  1265. Inverse: true,
  1266. Table: user.FollowersTable,
  1267. Columns: user.FollowersPrimaryKey,
  1268. Bidi: false,
  1269. Target: &sqlgraph.EdgeTarget{
  1270. IDSpec: &sqlgraph.FieldSpec{
  1271. Type: field.TypeInt,
  1272. Column: user.FieldID,
  1273. },
  1274. },
  1275. }
  1276. for _, k := range nodes {
  1277. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1278. }
  1279. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1280. }
  1281. if nodes := uuo.mutation.FollowersIDs(); len(nodes) > 0 {
  1282. edge := &sqlgraph.EdgeSpec{
  1283. Rel: sqlgraph.M2M,
  1284. Inverse: true,
  1285. Table: user.FollowersTable,
  1286. Columns: user.FollowersPrimaryKey,
  1287. Bidi: false,
  1288. Target: &sqlgraph.EdgeTarget{
  1289. IDSpec: &sqlgraph.FieldSpec{
  1290. Type: field.TypeInt,
  1291. Column: user.FieldID,
  1292. },
  1293. },
  1294. }
  1295. for _, k := range nodes {
  1296. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1297. }
  1298. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1299. }
  1300. if uuo.mutation.FollowingCleared() {
  1301. edge := &sqlgraph.EdgeSpec{
  1302. Rel: sqlgraph.M2M,
  1303. Inverse: false,
  1304. Table: user.FollowingTable,
  1305. Columns: user.FollowingPrimaryKey,
  1306. Bidi: false,
  1307. Target: &sqlgraph.EdgeTarget{
  1308. IDSpec: &sqlgraph.FieldSpec{
  1309. Type: field.TypeInt,
  1310. Column: user.FieldID,
  1311. },
  1312. },
  1313. }
  1314. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1315. }
  1316. if nodes := uuo.mutation.RemovedFollowingIDs(); len(nodes) > 0 && !uuo.mutation.FollowingCleared() {
  1317. edge := &sqlgraph.EdgeSpec{
  1318. Rel: sqlgraph.M2M,
  1319. Inverse: false,
  1320. Table: user.FollowingTable,
  1321. Columns: user.FollowingPrimaryKey,
  1322. Bidi: false,
  1323. Target: &sqlgraph.EdgeTarget{
  1324. IDSpec: &sqlgraph.FieldSpec{
  1325. Type: field.TypeInt,
  1326. Column: user.FieldID,
  1327. },
  1328. },
  1329. }
  1330. for _, k := range nodes {
  1331. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1332. }
  1333. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1334. }
  1335. if nodes := uuo.mutation.FollowingIDs(); len(nodes) > 0 {
  1336. edge := &sqlgraph.EdgeSpec{
  1337. Rel: sqlgraph.M2M,
  1338. Inverse: false,
  1339. Table: user.FollowingTable,
  1340. Columns: user.FollowingPrimaryKey,
  1341. Bidi: false,
  1342. Target: &sqlgraph.EdgeTarget{
  1343. IDSpec: &sqlgraph.FieldSpec{
  1344. Type: field.TypeInt,
  1345. Column: user.FieldID,
  1346. },
  1347. },
  1348. }
  1349. for _, k := range nodes {
  1350. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1351. }
  1352. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1353. }
  1354. if uuo.mutation.FriendsCleared() {
  1355. edge := &sqlgraph.EdgeSpec{
  1356. Rel: sqlgraph.M2M,
  1357. Inverse: false,
  1358. Table: user.FriendsTable,
  1359. Columns: user.FriendsPrimaryKey,
  1360. Bidi: true,
  1361. Target: &sqlgraph.EdgeTarget{
  1362. IDSpec: &sqlgraph.FieldSpec{
  1363. Type: field.TypeInt,
  1364. Column: user.FieldID,
  1365. },
  1366. },
  1367. }
  1368. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1369. }
  1370. if nodes := uuo.mutation.RemovedFriendsIDs(); len(nodes) > 0 && !uuo.mutation.FriendsCleared() {
  1371. edge := &sqlgraph.EdgeSpec{
  1372. Rel: sqlgraph.M2M,
  1373. Inverse: false,
  1374. Table: user.FriendsTable,
  1375. Columns: user.FriendsPrimaryKey,
  1376. Bidi: true,
  1377. Target: &sqlgraph.EdgeTarget{
  1378. IDSpec: &sqlgraph.FieldSpec{
  1379. Type: field.TypeInt,
  1380. Column: user.FieldID,
  1381. },
  1382. },
  1383. }
  1384. for _, k := range nodes {
  1385. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1386. }
  1387. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1388. }
  1389. if nodes := uuo.mutation.FriendsIDs(); len(nodes) > 0 {
  1390. edge := &sqlgraph.EdgeSpec{
  1391. Rel: sqlgraph.M2M,
  1392. Inverse: false,
  1393. Table: user.FriendsTable,
  1394. Columns: user.FriendsPrimaryKey,
  1395. Bidi: true,
  1396. Target: &sqlgraph.EdgeTarget{
  1397. IDSpec: &sqlgraph.FieldSpec{
  1398. Type: field.TypeInt,
  1399. Column: user.FieldID,
  1400. },
  1401. },
  1402. }
  1403. for _, k := range nodes {
  1404. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1405. }
  1406. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1407. }
  1408. _node = &User{config: uuo.config}
  1409. _spec.Assign = _node.assignValues
  1410. _spec.ScanValues = _node.scanValues
  1411. if err = sqlgraph.UpdateNode(ctx, uuo.driver, _spec); err != nil {
  1412. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  1413. err = &NotFoundError{user.Label}
  1414. } else if sqlgraph.IsConstraintError(err) {
  1415. err = &ConstraintError{err.Error(), err}
  1416. }
  1417. return nil, err
  1418. }
  1419. return _node, nil
  1420. }