tutorial_update.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "time"
  8. "wechat-api/ent/employee"
  9. "wechat-api/ent/predicate"
  10. "wechat-api/ent/tutorial"
  11. "entgo.io/ent/dialect/sql"
  12. "entgo.io/ent/dialect/sql/sqlgraph"
  13. "entgo.io/ent/schema/field"
  14. )
  15. // TutorialUpdate is the builder for updating Tutorial entities.
  16. type TutorialUpdate struct {
  17. config
  18. hooks []Hook
  19. mutation *TutorialMutation
  20. }
  21. // Where appends a list predicates to the TutorialUpdate builder.
  22. func (tu *TutorialUpdate) Where(ps ...predicate.Tutorial) *TutorialUpdate {
  23. tu.mutation.Where(ps...)
  24. return tu
  25. }
  26. // SetUpdatedAt sets the "updated_at" field.
  27. func (tu *TutorialUpdate) SetUpdatedAt(t time.Time) *TutorialUpdate {
  28. tu.mutation.SetUpdatedAt(t)
  29. return tu
  30. }
  31. // SetDeletedAt sets the "deleted_at" field.
  32. func (tu *TutorialUpdate) SetDeletedAt(t time.Time) *TutorialUpdate {
  33. tu.mutation.SetDeletedAt(t)
  34. return tu
  35. }
  36. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  37. func (tu *TutorialUpdate) SetNillableDeletedAt(t *time.Time) *TutorialUpdate {
  38. if t != nil {
  39. tu.SetDeletedAt(*t)
  40. }
  41. return tu
  42. }
  43. // ClearDeletedAt clears the value of the "deleted_at" field.
  44. func (tu *TutorialUpdate) ClearDeletedAt() *TutorialUpdate {
  45. tu.mutation.ClearDeletedAt()
  46. return tu
  47. }
  48. // SetEmployeeID sets the "employee_id" field.
  49. func (tu *TutorialUpdate) SetEmployeeID(u uint64) *TutorialUpdate {
  50. tu.mutation.SetEmployeeID(u)
  51. return tu
  52. }
  53. // SetNillableEmployeeID sets the "employee_id" field if the given value is not nil.
  54. func (tu *TutorialUpdate) SetNillableEmployeeID(u *uint64) *TutorialUpdate {
  55. if u != nil {
  56. tu.SetEmployeeID(*u)
  57. }
  58. return tu
  59. }
  60. // SetIndex sets the "index" field.
  61. func (tu *TutorialUpdate) SetIndex(i int) *TutorialUpdate {
  62. tu.mutation.ResetIndex()
  63. tu.mutation.SetIndex(i)
  64. return tu
  65. }
  66. // SetNillableIndex sets the "index" field if the given value is not nil.
  67. func (tu *TutorialUpdate) SetNillableIndex(i *int) *TutorialUpdate {
  68. if i != nil {
  69. tu.SetIndex(*i)
  70. }
  71. return tu
  72. }
  73. // AddIndex adds i to the "index" field.
  74. func (tu *TutorialUpdate) AddIndex(i int) *TutorialUpdate {
  75. tu.mutation.AddIndex(i)
  76. return tu
  77. }
  78. // SetTitle sets the "title" field.
  79. func (tu *TutorialUpdate) SetTitle(s string) *TutorialUpdate {
  80. tu.mutation.SetTitle(s)
  81. return tu
  82. }
  83. // SetNillableTitle sets the "title" field if the given value is not nil.
  84. func (tu *TutorialUpdate) SetNillableTitle(s *string) *TutorialUpdate {
  85. if s != nil {
  86. tu.SetTitle(*s)
  87. }
  88. return tu
  89. }
  90. // SetContent sets the "content" field.
  91. func (tu *TutorialUpdate) SetContent(s string) *TutorialUpdate {
  92. tu.mutation.SetContent(s)
  93. return tu
  94. }
  95. // SetNillableContent sets the "content" field if the given value is not nil.
  96. func (tu *TutorialUpdate) SetNillableContent(s *string) *TutorialUpdate {
  97. if s != nil {
  98. tu.SetContent(*s)
  99. }
  100. return tu
  101. }
  102. // SetOrganizationID sets the "organization_id" field.
  103. func (tu *TutorialUpdate) SetOrganizationID(u uint64) *TutorialUpdate {
  104. tu.mutation.ResetOrganizationID()
  105. tu.mutation.SetOrganizationID(u)
  106. return tu
  107. }
  108. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  109. func (tu *TutorialUpdate) SetNillableOrganizationID(u *uint64) *TutorialUpdate {
  110. if u != nil {
  111. tu.SetOrganizationID(*u)
  112. }
  113. return tu
  114. }
  115. // AddOrganizationID adds u to the "organization_id" field.
  116. func (tu *TutorialUpdate) AddOrganizationID(u int64) *TutorialUpdate {
  117. tu.mutation.AddOrganizationID(u)
  118. return tu
  119. }
  120. // SetEmployee sets the "employee" edge to the Employee entity.
  121. func (tu *TutorialUpdate) SetEmployee(e *Employee) *TutorialUpdate {
  122. return tu.SetEmployeeID(e.ID)
  123. }
  124. // Mutation returns the TutorialMutation object of the builder.
  125. func (tu *TutorialUpdate) Mutation() *TutorialMutation {
  126. return tu.mutation
  127. }
  128. // ClearEmployee clears the "employee" edge to the Employee entity.
  129. func (tu *TutorialUpdate) ClearEmployee() *TutorialUpdate {
  130. tu.mutation.ClearEmployee()
  131. return tu
  132. }
  133. // Save executes the query and returns the number of nodes affected by the update operation.
  134. func (tu *TutorialUpdate) Save(ctx context.Context) (int, error) {
  135. if err := tu.defaults(); err != nil {
  136. return 0, err
  137. }
  138. return withHooks(ctx, tu.sqlSave, tu.mutation, tu.hooks)
  139. }
  140. // SaveX is like Save, but panics if an error occurs.
  141. func (tu *TutorialUpdate) SaveX(ctx context.Context) int {
  142. affected, err := tu.Save(ctx)
  143. if err != nil {
  144. panic(err)
  145. }
  146. return affected
  147. }
  148. // Exec executes the query.
  149. func (tu *TutorialUpdate) Exec(ctx context.Context) error {
  150. _, err := tu.Save(ctx)
  151. return err
  152. }
  153. // ExecX is like Exec, but panics if an error occurs.
  154. func (tu *TutorialUpdate) ExecX(ctx context.Context) {
  155. if err := tu.Exec(ctx); err != nil {
  156. panic(err)
  157. }
  158. }
  159. // defaults sets the default values of the builder before save.
  160. func (tu *TutorialUpdate) defaults() error {
  161. if _, ok := tu.mutation.UpdatedAt(); !ok {
  162. if tutorial.UpdateDefaultUpdatedAt == nil {
  163. return fmt.Errorf("ent: uninitialized tutorial.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  164. }
  165. v := tutorial.UpdateDefaultUpdatedAt()
  166. tu.mutation.SetUpdatedAt(v)
  167. }
  168. return nil
  169. }
  170. // check runs all checks and user-defined validators on the builder.
  171. func (tu *TutorialUpdate) check() error {
  172. if v, ok := tu.mutation.EmployeeID(); ok {
  173. if err := tutorial.EmployeeIDValidator(v); err != nil {
  174. return &ValidationError{Name: "employee_id", err: fmt.Errorf(`ent: validator failed for field "Tutorial.employee_id": %w`, err)}
  175. }
  176. }
  177. if v, ok := tu.mutation.OrganizationID(); ok {
  178. if err := tutorial.OrganizationIDValidator(v); err != nil {
  179. return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Tutorial.organization_id": %w`, err)}
  180. }
  181. }
  182. if _, ok := tu.mutation.EmployeeID(); tu.mutation.EmployeeCleared() && !ok {
  183. return errors.New(`ent: clearing a required unique edge "Tutorial.employee"`)
  184. }
  185. return nil
  186. }
  187. func (tu *TutorialUpdate) sqlSave(ctx context.Context) (n int, err error) {
  188. if err := tu.check(); err != nil {
  189. return n, err
  190. }
  191. _spec := sqlgraph.NewUpdateSpec(tutorial.Table, tutorial.Columns, sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64))
  192. if ps := tu.mutation.predicates; len(ps) > 0 {
  193. _spec.Predicate = func(selector *sql.Selector) {
  194. for i := range ps {
  195. ps[i](selector)
  196. }
  197. }
  198. }
  199. if value, ok := tu.mutation.UpdatedAt(); ok {
  200. _spec.SetField(tutorial.FieldUpdatedAt, field.TypeTime, value)
  201. }
  202. if value, ok := tu.mutation.DeletedAt(); ok {
  203. _spec.SetField(tutorial.FieldDeletedAt, field.TypeTime, value)
  204. }
  205. if tu.mutation.DeletedAtCleared() {
  206. _spec.ClearField(tutorial.FieldDeletedAt, field.TypeTime)
  207. }
  208. if value, ok := tu.mutation.Index(); ok {
  209. _spec.SetField(tutorial.FieldIndex, field.TypeInt, value)
  210. }
  211. if value, ok := tu.mutation.AddedIndex(); ok {
  212. _spec.AddField(tutorial.FieldIndex, field.TypeInt, value)
  213. }
  214. if value, ok := tu.mutation.Title(); ok {
  215. _spec.SetField(tutorial.FieldTitle, field.TypeString, value)
  216. }
  217. if value, ok := tu.mutation.Content(); ok {
  218. _spec.SetField(tutorial.FieldContent, field.TypeString, value)
  219. }
  220. if value, ok := tu.mutation.OrganizationID(); ok {
  221. _spec.SetField(tutorial.FieldOrganizationID, field.TypeUint64, value)
  222. }
  223. if value, ok := tu.mutation.AddedOrganizationID(); ok {
  224. _spec.AddField(tutorial.FieldOrganizationID, field.TypeUint64, value)
  225. }
  226. if tu.mutation.EmployeeCleared() {
  227. edge := &sqlgraph.EdgeSpec{
  228. Rel: sqlgraph.M2O,
  229. Inverse: true,
  230. Table: tutorial.EmployeeTable,
  231. Columns: []string{tutorial.EmployeeColumn},
  232. Bidi: false,
  233. Target: &sqlgraph.EdgeTarget{
  234. IDSpec: sqlgraph.NewFieldSpec(employee.FieldID, field.TypeUint64),
  235. },
  236. }
  237. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  238. }
  239. if nodes := tu.mutation.EmployeeIDs(); len(nodes) > 0 {
  240. edge := &sqlgraph.EdgeSpec{
  241. Rel: sqlgraph.M2O,
  242. Inverse: true,
  243. Table: tutorial.EmployeeTable,
  244. Columns: []string{tutorial.EmployeeColumn},
  245. Bidi: false,
  246. Target: &sqlgraph.EdgeTarget{
  247. IDSpec: sqlgraph.NewFieldSpec(employee.FieldID, field.TypeUint64),
  248. },
  249. }
  250. for _, k := range nodes {
  251. edge.Target.Nodes = append(edge.Target.Nodes, k)
  252. }
  253. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  254. }
  255. if n, err = sqlgraph.UpdateNodes(ctx, tu.driver, _spec); err != nil {
  256. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  257. err = &NotFoundError{tutorial.Label}
  258. } else if sqlgraph.IsConstraintError(err) {
  259. err = &ConstraintError{msg: err.Error(), wrap: err}
  260. }
  261. return 0, err
  262. }
  263. tu.mutation.done = true
  264. return n, nil
  265. }
  266. // TutorialUpdateOne is the builder for updating a single Tutorial entity.
  267. type TutorialUpdateOne struct {
  268. config
  269. fields []string
  270. hooks []Hook
  271. mutation *TutorialMutation
  272. }
  273. // SetUpdatedAt sets the "updated_at" field.
  274. func (tuo *TutorialUpdateOne) SetUpdatedAt(t time.Time) *TutorialUpdateOne {
  275. tuo.mutation.SetUpdatedAt(t)
  276. return tuo
  277. }
  278. // SetDeletedAt sets the "deleted_at" field.
  279. func (tuo *TutorialUpdateOne) SetDeletedAt(t time.Time) *TutorialUpdateOne {
  280. tuo.mutation.SetDeletedAt(t)
  281. return tuo
  282. }
  283. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  284. func (tuo *TutorialUpdateOne) SetNillableDeletedAt(t *time.Time) *TutorialUpdateOne {
  285. if t != nil {
  286. tuo.SetDeletedAt(*t)
  287. }
  288. return tuo
  289. }
  290. // ClearDeletedAt clears the value of the "deleted_at" field.
  291. func (tuo *TutorialUpdateOne) ClearDeletedAt() *TutorialUpdateOne {
  292. tuo.mutation.ClearDeletedAt()
  293. return tuo
  294. }
  295. // SetEmployeeID sets the "employee_id" field.
  296. func (tuo *TutorialUpdateOne) SetEmployeeID(u uint64) *TutorialUpdateOne {
  297. tuo.mutation.SetEmployeeID(u)
  298. return tuo
  299. }
  300. // SetNillableEmployeeID sets the "employee_id" field if the given value is not nil.
  301. func (tuo *TutorialUpdateOne) SetNillableEmployeeID(u *uint64) *TutorialUpdateOne {
  302. if u != nil {
  303. tuo.SetEmployeeID(*u)
  304. }
  305. return tuo
  306. }
  307. // SetIndex sets the "index" field.
  308. func (tuo *TutorialUpdateOne) SetIndex(i int) *TutorialUpdateOne {
  309. tuo.mutation.ResetIndex()
  310. tuo.mutation.SetIndex(i)
  311. return tuo
  312. }
  313. // SetNillableIndex sets the "index" field if the given value is not nil.
  314. func (tuo *TutorialUpdateOne) SetNillableIndex(i *int) *TutorialUpdateOne {
  315. if i != nil {
  316. tuo.SetIndex(*i)
  317. }
  318. return tuo
  319. }
  320. // AddIndex adds i to the "index" field.
  321. func (tuo *TutorialUpdateOne) AddIndex(i int) *TutorialUpdateOne {
  322. tuo.mutation.AddIndex(i)
  323. return tuo
  324. }
  325. // SetTitle sets the "title" field.
  326. func (tuo *TutorialUpdateOne) SetTitle(s string) *TutorialUpdateOne {
  327. tuo.mutation.SetTitle(s)
  328. return tuo
  329. }
  330. // SetNillableTitle sets the "title" field if the given value is not nil.
  331. func (tuo *TutorialUpdateOne) SetNillableTitle(s *string) *TutorialUpdateOne {
  332. if s != nil {
  333. tuo.SetTitle(*s)
  334. }
  335. return tuo
  336. }
  337. // SetContent sets the "content" field.
  338. func (tuo *TutorialUpdateOne) SetContent(s string) *TutorialUpdateOne {
  339. tuo.mutation.SetContent(s)
  340. return tuo
  341. }
  342. // SetNillableContent sets the "content" field if the given value is not nil.
  343. func (tuo *TutorialUpdateOne) SetNillableContent(s *string) *TutorialUpdateOne {
  344. if s != nil {
  345. tuo.SetContent(*s)
  346. }
  347. return tuo
  348. }
  349. // SetOrganizationID sets the "organization_id" field.
  350. func (tuo *TutorialUpdateOne) SetOrganizationID(u uint64) *TutorialUpdateOne {
  351. tuo.mutation.ResetOrganizationID()
  352. tuo.mutation.SetOrganizationID(u)
  353. return tuo
  354. }
  355. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  356. func (tuo *TutorialUpdateOne) SetNillableOrganizationID(u *uint64) *TutorialUpdateOne {
  357. if u != nil {
  358. tuo.SetOrganizationID(*u)
  359. }
  360. return tuo
  361. }
  362. // AddOrganizationID adds u to the "organization_id" field.
  363. func (tuo *TutorialUpdateOne) AddOrganizationID(u int64) *TutorialUpdateOne {
  364. tuo.mutation.AddOrganizationID(u)
  365. return tuo
  366. }
  367. // SetEmployee sets the "employee" edge to the Employee entity.
  368. func (tuo *TutorialUpdateOne) SetEmployee(e *Employee) *TutorialUpdateOne {
  369. return tuo.SetEmployeeID(e.ID)
  370. }
  371. // Mutation returns the TutorialMutation object of the builder.
  372. func (tuo *TutorialUpdateOne) Mutation() *TutorialMutation {
  373. return tuo.mutation
  374. }
  375. // ClearEmployee clears the "employee" edge to the Employee entity.
  376. func (tuo *TutorialUpdateOne) ClearEmployee() *TutorialUpdateOne {
  377. tuo.mutation.ClearEmployee()
  378. return tuo
  379. }
  380. // Where appends a list predicates to the TutorialUpdate builder.
  381. func (tuo *TutorialUpdateOne) Where(ps ...predicate.Tutorial) *TutorialUpdateOne {
  382. tuo.mutation.Where(ps...)
  383. return tuo
  384. }
  385. // Select allows selecting one or more fields (columns) of the returned entity.
  386. // The default is selecting all fields defined in the entity schema.
  387. func (tuo *TutorialUpdateOne) Select(field string, fields ...string) *TutorialUpdateOne {
  388. tuo.fields = append([]string{field}, fields...)
  389. return tuo
  390. }
  391. // Save executes the query and returns the updated Tutorial entity.
  392. func (tuo *TutorialUpdateOne) Save(ctx context.Context) (*Tutorial, error) {
  393. if err := tuo.defaults(); err != nil {
  394. return nil, err
  395. }
  396. return withHooks(ctx, tuo.sqlSave, tuo.mutation, tuo.hooks)
  397. }
  398. // SaveX is like Save, but panics if an error occurs.
  399. func (tuo *TutorialUpdateOne) SaveX(ctx context.Context) *Tutorial {
  400. node, err := tuo.Save(ctx)
  401. if err != nil {
  402. panic(err)
  403. }
  404. return node
  405. }
  406. // Exec executes the query on the entity.
  407. func (tuo *TutorialUpdateOne) Exec(ctx context.Context) error {
  408. _, err := tuo.Save(ctx)
  409. return err
  410. }
  411. // ExecX is like Exec, but panics if an error occurs.
  412. func (tuo *TutorialUpdateOne) ExecX(ctx context.Context) {
  413. if err := tuo.Exec(ctx); err != nil {
  414. panic(err)
  415. }
  416. }
  417. // defaults sets the default values of the builder before save.
  418. func (tuo *TutorialUpdateOne) defaults() error {
  419. if _, ok := tuo.mutation.UpdatedAt(); !ok {
  420. if tutorial.UpdateDefaultUpdatedAt == nil {
  421. return fmt.Errorf("ent: uninitialized tutorial.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  422. }
  423. v := tutorial.UpdateDefaultUpdatedAt()
  424. tuo.mutation.SetUpdatedAt(v)
  425. }
  426. return nil
  427. }
  428. // check runs all checks and user-defined validators on the builder.
  429. func (tuo *TutorialUpdateOne) check() error {
  430. if v, ok := tuo.mutation.EmployeeID(); ok {
  431. if err := tutorial.EmployeeIDValidator(v); err != nil {
  432. return &ValidationError{Name: "employee_id", err: fmt.Errorf(`ent: validator failed for field "Tutorial.employee_id": %w`, err)}
  433. }
  434. }
  435. if v, ok := tuo.mutation.OrganizationID(); ok {
  436. if err := tutorial.OrganizationIDValidator(v); err != nil {
  437. return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Tutorial.organization_id": %w`, err)}
  438. }
  439. }
  440. if _, ok := tuo.mutation.EmployeeID(); tuo.mutation.EmployeeCleared() && !ok {
  441. return errors.New(`ent: clearing a required unique edge "Tutorial.employee"`)
  442. }
  443. return nil
  444. }
  445. func (tuo *TutorialUpdateOne) sqlSave(ctx context.Context) (_node *Tutorial, err error) {
  446. if err := tuo.check(); err != nil {
  447. return _node, err
  448. }
  449. _spec := sqlgraph.NewUpdateSpec(tutorial.Table, tutorial.Columns, sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64))
  450. id, ok := tuo.mutation.ID()
  451. if !ok {
  452. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Tutorial.id" for update`)}
  453. }
  454. _spec.Node.ID.Value = id
  455. if fields := tuo.fields; len(fields) > 0 {
  456. _spec.Node.Columns = make([]string, 0, len(fields))
  457. _spec.Node.Columns = append(_spec.Node.Columns, tutorial.FieldID)
  458. for _, f := range fields {
  459. if !tutorial.ValidColumn(f) {
  460. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  461. }
  462. if f != tutorial.FieldID {
  463. _spec.Node.Columns = append(_spec.Node.Columns, f)
  464. }
  465. }
  466. }
  467. if ps := tuo.mutation.predicates; len(ps) > 0 {
  468. _spec.Predicate = func(selector *sql.Selector) {
  469. for i := range ps {
  470. ps[i](selector)
  471. }
  472. }
  473. }
  474. if value, ok := tuo.mutation.UpdatedAt(); ok {
  475. _spec.SetField(tutorial.FieldUpdatedAt, field.TypeTime, value)
  476. }
  477. if value, ok := tuo.mutation.DeletedAt(); ok {
  478. _spec.SetField(tutorial.FieldDeletedAt, field.TypeTime, value)
  479. }
  480. if tuo.mutation.DeletedAtCleared() {
  481. _spec.ClearField(tutorial.FieldDeletedAt, field.TypeTime)
  482. }
  483. if value, ok := tuo.mutation.Index(); ok {
  484. _spec.SetField(tutorial.FieldIndex, field.TypeInt, value)
  485. }
  486. if value, ok := tuo.mutation.AddedIndex(); ok {
  487. _spec.AddField(tutorial.FieldIndex, field.TypeInt, value)
  488. }
  489. if value, ok := tuo.mutation.Title(); ok {
  490. _spec.SetField(tutorial.FieldTitle, field.TypeString, value)
  491. }
  492. if value, ok := tuo.mutation.Content(); ok {
  493. _spec.SetField(tutorial.FieldContent, field.TypeString, value)
  494. }
  495. if value, ok := tuo.mutation.OrganizationID(); ok {
  496. _spec.SetField(tutorial.FieldOrganizationID, field.TypeUint64, value)
  497. }
  498. if value, ok := tuo.mutation.AddedOrganizationID(); ok {
  499. _spec.AddField(tutorial.FieldOrganizationID, field.TypeUint64, value)
  500. }
  501. if tuo.mutation.EmployeeCleared() {
  502. edge := &sqlgraph.EdgeSpec{
  503. Rel: sqlgraph.M2O,
  504. Inverse: true,
  505. Table: tutorial.EmployeeTable,
  506. Columns: []string{tutorial.EmployeeColumn},
  507. Bidi: false,
  508. Target: &sqlgraph.EdgeTarget{
  509. IDSpec: sqlgraph.NewFieldSpec(employee.FieldID, field.TypeUint64),
  510. },
  511. }
  512. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  513. }
  514. if nodes := tuo.mutation.EmployeeIDs(); len(nodes) > 0 {
  515. edge := &sqlgraph.EdgeSpec{
  516. Rel: sqlgraph.M2O,
  517. Inverse: true,
  518. Table: tutorial.EmployeeTable,
  519. Columns: []string{tutorial.EmployeeColumn},
  520. Bidi: false,
  521. Target: &sqlgraph.EdgeTarget{
  522. IDSpec: sqlgraph.NewFieldSpec(employee.FieldID, field.TypeUint64),
  523. },
  524. }
  525. for _, k := range nodes {
  526. edge.Target.Nodes = append(edge.Target.Nodes, k)
  527. }
  528. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  529. }
  530. _node = &Tutorial{config: tuo.config}
  531. _spec.Assign = _node.assignValues
  532. _spec.ScanValues = _node.scanValues
  533. if err = sqlgraph.UpdateNode(ctx, tuo.driver, _spec); err != nil {
  534. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  535. err = &NotFoundError{tutorial.Label}
  536. } else if sqlgraph.IsConstraintError(err) {
  537. err = &ConstraintError{msg: err.Error(), wrap: err}
  538. }
  539. return nil, err
  540. }
  541. tuo.mutation.done = true
  542. return _node, nil
  543. }