sopstage_update.go 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189
  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/custom_types"
  9. "wechat-api/ent/messagerecords"
  10. "wechat-api/ent/predicate"
  11. "wechat-api/ent/sopnode"
  12. "wechat-api/ent/sopstage"
  13. "wechat-api/ent/soptask"
  14. "entgo.io/ent/dialect/sql"
  15. "entgo.io/ent/dialect/sql/sqlgraph"
  16. "entgo.io/ent/dialect/sql/sqljson"
  17. "entgo.io/ent/schema/field"
  18. )
  19. // SopStageUpdate is the builder for updating SopStage entities.
  20. type SopStageUpdate struct {
  21. config
  22. hooks []Hook
  23. mutation *SopStageMutation
  24. }
  25. // Where appends a list predicates to the SopStageUpdate builder.
  26. func (ssu *SopStageUpdate) Where(ps ...predicate.SopStage) *SopStageUpdate {
  27. ssu.mutation.Where(ps...)
  28. return ssu
  29. }
  30. // SetUpdatedAt sets the "updated_at" field.
  31. func (ssu *SopStageUpdate) SetUpdatedAt(t time.Time) *SopStageUpdate {
  32. ssu.mutation.SetUpdatedAt(t)
  33. return ssu
  34. }
  35. // SetStatus sets the "status" field.
  36. func (ssu *SopStageUpdate) SetStatus(u uint8) *SopStageUpdate {
  37. ssu.mutation.ResetStatus()
  38. ssu.mutation.SetStatus(u)
  39. return ssu
  40. }
  41. // SetNillableStatus sets the "status" field if the given value is not nil.
  42. func (ssu *SopStageUpdate) SetNillableStatus(u *uint8) *SopStageUpdate {
  43. if u != nil {
  44. ssu.SetStatus(*u)
  45. }
  46. return ssu
  47. }
  48. // AddStatus adds u to the "status" field.
  49. func (ssu *SopStageUpdate) AddStatus(u int8) *SopStageUpdate {
  50. ssu.mutation.AddStatus(u)
  51. return ssu
  52. }
  53. // ClearStatus clears the value of the "status" field.
  54. func (ssu *SopStageUpdate) ClearStatus() *SopStageUpdate {
  55. ssu.mutation.ClearStatus()
  56. return ssu
  57. }
  58. // SetDeletedAt sets the "deleted_at" field.
  59. func (ssu *SopStageUpdate) SetDeletedAt(t time.Time) *SopStageUpdate {
  60. ssu.mutation.SetDeletedAt(t)
  61. return ssu
  62. }
  63. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  64. func (ssu *SopStageUpdate) SetNillableDeletedAt(t *time.Time) *SopStageUpdate {
  65. if t != nil {
  66. ssu.SetDeletedAt(*t)
  67. }
  68. return ssu
  69. }
  70. // ClearDeletedAt clears the value of the "deleted_at" field.
  71. func (ssu *SopStageUpdate) ClearDeletedAt() *SopStageUpdate {
  72. ssu.mutation.ClearDeletedAt()
  73. return ssu
  74. }
  75. // SetTaskID sets the "task_id" field.
  76. func (ssu *SopStageUpdate) SetTaskID(u uint64) *SopStageUpdate {
  77. ssu.mutation.SetTaskID(u)
  78. return ssu
  79. }
  80. // SetNillableTaskID sets the "task_id" field if the given value is not nil.
  81. func (ssu *SopStageUpdate) SetNillableTaskID(u *uint64) *SopStageUpdate {
  82. if u != nil {
  83. ssu.SetTaskID(*u)
  84. }
  85. return ssu
  86. }
  87. // SetName sets the "name" field.
  88. func (ssu *SopStageUpdate) SetName(s string) *SopStageUpdate {
  89. ssu.mutation.SetName(s)
  90. return ssu
  91. }
  92. // SetNillableName sets the "name" field if the given value is not nil.
  93. func (ssu *SopStageUpdate) SetNillableName(s *string) *SopStageUpdate {
  94. if s != nil {
  95. ssu.SetName(*s)
  96. }
  97. return ssu
  98. }
  99. // SetConditionType sets the "condition_type" field.
  100. func (ssu *SopStageUpdate) SetConditionType(i int) *SopStageUpdate {
  101. ssu.mutation.ResetConditionType()
  102. ssu.mutation.SetConditionType(i)
  103. return ssu
  104. }
  105. // SetNillableConditionType sets the "condition_type" field if the given value is not nil.
  106. func (ssu *SopStageUpdate) SetNillableConditionType(i *int) *SopStageUpdate {
  107. if i != nil {
  108. ssu.SetConditionType(*i)
  109. }
  110. return ssu
  111. }
  112. // AddConditionType adds i to the "condition_type" field.
  113. func (ssu *SopStageUpdate) AddConditionType(i int) *SopStageUpdate {
  114. ssu.mutation.AddConditionType(i)
  115. return ssu
  116. }
  117. // SetConditionOperator sets the "condition_operator" field.
  118. func (ssu *SopStageUpdate) SetConditionOperator(i int) *SopStageUpdate {
  119. ssu.mutation.ResetConditionOperator()
  120. ssu.mutation.SetConditionOperator(i)
  121. return ssu
  122. }
  123. // SetNillableConditionOperator sets the "condition_operator" field if the given value is not nil.
  124. func (ssu *SopStageUpdate) SetNillableConditionOperator(i *int) *SopStageUpdate {
  125. if i != nil {
  126. ssu.SetConditionOperator(*i)
  127. }
  128. return ssu
  129. }
  130. // AddConditionOperator adds i to the "condition_operator" field.
  131. func (ssu *SopStageUpdate) AddConditionOperator(i int) *SopStageUpdate {
  132. ssu.mutation.AddConditionOperator(i)
  133. return ssu
  134. }
  135. // SetConditionList sets the "condition_list" field.
  136. func (ssu *SopStageUpdate) SetConditionList(ct []custom_types.Condition) *SopStageUpdate {
  137. ssu.mutation.SetConditionList(ct)
  138. return ssu
  139. }
  140. // AppendConditionList appends ct to the "condition_list" field.
  141. func (ssu *SopStageUpdate) AppendConditionList(ct []custom_types.Condition) *SopStageUpdate {
  142. ssu.mutation.AppendConditionList(ct)
  143. return ssu
  144. }
  145. // SetActionMessage sets the "action_message" field.
  146. func (ssu *SopStageUpdate) SetActionMessage(ct []custom_types.Action) *SopStageUpdate {
  147. ssu.mutation.SetActionMessage(ct)
  148. return ssu
  149. }
  150. // AppendActionMessage appends ct to the "action_message" field.
  151. func (ssu *SopStageUpdate) AppendActionMessage(ct []custom_types.Action) *SopStageUpdate {
  152. ssu.mutation.AppendActionMessage(ct)
  153. return ssu
  154. }
  155. // ClearActionMessage clears the value of the "action_message" field.
  156. func (ssu *SopStageUpdate) ClearActionMessage() *SopStageUpdate {
  157. ssu.mutation.ClearActionMessage()
  158. return ssu
  159. }
  160. // SetActionLabel sets the "action_label" field.
  161. func (ssu *SopStageUpdate) SetActionLabel(u []uint64) *SopStageUpdate {
  162. ssu.mutation.SetActionLabel(u)
  163. return ssu
  164. }
  165. // AppendActionLabel appends u to the "action_label" field.
  166. func (ssu *SopStageUpdate) AppendActionLabel(u []uint64) *SopStageUpdate {
  167. ssu.mutation.AppendActionLabel(u)
  168. return ssu
  169. }
  170. // ClearActionLabel clears the value of the "action_label" field.
  171. func (ssu *SopStageUpdate) ClearActionLabel() *SopStageUpdate {
  172. ssu.mutation.ClearActionLabel()
  173. return ssu
  174. }
  175. // SetIndexSort sets the "index_sort" field.
  176. func (ssu *SopStageUpdate) SetIndexSort(i int) *SopStageUpdate {
  177. ssu.mutation.ResetIndexSort()
  178. ssu.mutation.SetIndexSort(i)
  179. return ssu
  180. }
  181. // SetNillableIndexSort sets the "index_sort" field if the given value is not nil.
  182. func (ssu *SopStageUpdate) SetNillableIndexSort(i *int) *SopStageUpdate {
  183. if i != nil {
  184. ssu.SetIndexSort(*i)
  185. }
  186. return ssu
  187. }
  188. // AddIndexSort adds i to the "index_sort" field.
  189. func (ssu *SopStageUpdate) AddIndexSort(i int) *SopStageUpdate {
  190. ssu.mutation.AddIndexSort(i)
  191. return ssu
  192. }
  193. // ClearIndexSort clears the value of the "index_sort" field.
  194. func (ssu *SopStageUpdate) ClearIndexSort() *SopStageUpdate {
  195. ssu.mutation.ClearIndexSort()
  196. return ssu
  197. }
  198. // SetSopTaskID sets the "sop_task" edge to the SopTask entity by ID.
  199. func (ssu *SopStageUpdate) SetSopTaskID(id uint64) *SopStageUpdate {
  200. ssu.mutation.SetSopTaskID(id)
  201. return ssu
  202. }
  203. // SetSopTask sets the "sop_task" edge to the SopTask entity.
  204. func (ssu *SopStageUpdate) SetSopTask(s *SopTask) *SopStageUpdate {
  205. return ssu.SetSopTaskID(s.ID)
  206. }
  207. // AddStageNodeIDs adds the "stage_nodes" edge to the SopNode entity by IDs.
  208. func (ssu *SopStageUpdate) AddStageNodeIDs(ids ...uint64) *SopStageUpdate {
  209. ssu.mutation.AddStageNodeIDs(ids...)
  210. return ssu
  211. }
  212. // AddStageNodes adds the "stage_nodes" edges to the SopNode entity.
  213. func (ssu *SopStageUpdate) AddStageNodes(s ...*SopNode) *SopStageUpdate {
  214. ids := make([]uint64, len(s))
  215. for i := range s {
  216. ids[i] = s[i].ID
  217. }
  218. return ssu.AddStageNodeIDs(ids...)
  219. }
  220. // AddStageMessageIDs adds the "stage_messages" edge to the MessageRecords entity by IDs.
  221. func (ssu *SopStageUpdate) AddStageMessageIDs(ids ...uint64) *SopStageUpdate {
  222. ssu.mutation.AddStageMessageIDs(ids...)
  223. return ssu
  224. }
  225. // AddStageMessages adds the "stage_messages" edges to the MessageRecords entity.
  226. func (ssu *SopStageUpdate) AddStageMessages(m ...*MessageRecords) *SopStageUpdate {
  227. ids := make([]uint64, len(m))
  228. for i := range m {
  229. ids[i] = m[i].ID
  230. }
  231. return ssu.AddStageMessageIDs(ids...)
  232. }
  233. // Mutation returns the SopStageMutation object of the builder.
  234. func (ssu *SopStageUpdate) Mutation() *SopStageMutation {
  235. return ssu.mutation
  236. }
  237. // ClearSopTask clears the "sop_task" edge to the SopTask entity.
  238. func (ssu *SopStageUpdate) ClearSopTask() *SopStageUpdate {
  239. ssu.mutation.ClearSopTask()
  240. return ssu
  241. }
  242. // ClearStageNodes clears all "stage_nodes" edges to the SopNode entity.
  243. func (ssu *SopStageUpdate) ClearStageNodes() *SopStageUpdate {
  244. ssu.mutation.ClearStageNodes()
  245. return ssu
  246. }
  247. // RemoveStageNodeIDs removes the "stage_nodes" edge to SopNode entities by IDs.
  248. func (ssu *SopStageUpdate) RemoveStageNodeIDs(ids ...uint64) *SopStageUpdate {
  249. ssu.mutation.RemoveStageNodeIDs(ids...)
  250. return ssu
  251. }
  252. // RemoveStageNodes removes "stage_nodes" edges to SopNode entities.
  253. func (ssu *SopStageUpdate) RemoveStageNodes(s ...*SopNode) *SopStageUpdate {
  254. ids := make([]uint64, len(s))
  255. for i := range s {
  256. ids[i] = s[i].ID
  257. }
  258. return ssu.RemoveStageNodeIDs(ids...)
  259. }
  260. // ClearStageMessages clears all "stage_messages" edges to the MessageRecords entity.
  261. func (ssu *SopStageUpdate) ClearStageMessages() *SopStageUpdate {
  262. ssu.mutation.ClearStageMessages()
  263. return ssu
  264. }
  265. // RemoveStageMessageIDs removes the "stage_messages" edge to MessageRecords entities by IDs.
  266. func (ssu *SopStageUpdate) RemoveStageMessageIDs(ids ...uint64) *SopStageUpdate {
  267. ssu.mutation.RemoveStageMessageIDs(ids...)
  268. return ssu
  269. }
  270. // RemoveStageMessages removes "stage_messages" edges to MessageRecords entities.
  271. func (ssu *SopStageUpdate) RemoveStageMessages(m ...*MessageRecords) *SopStageUpdate {
  272. ids := make([]uint64, len(m))
  273. for i := range m {
  274. ids[i] = m[i].ID
  275. }
  276. return ssu.RemoveStageMessageIDs(ids...)
  277. }
  278. // Save executes the query and returns the number of nodes affected by the update operation.
  279. func (ssu *SopStageUpdate) Save(ctx context.Context) (int, error) {
  280. if err := ssu.defaults(); err != nil {
  281. return 0, err
  282. }
  283. return withHooks(ctx, ssu.sqlSave, ssu.mutation, ssu.hooks)
  284. }
  285. // SaveX is like Save, but panics if an error occurs.
  286. func (ssu *SopStageUpdate) SaveX(ctx context.Context) int {
  287. affected, err := ssu.Save(ctx)
  288. if err != nil {
  289. panic(err)
  290. }
  291. return affected
  292. }
  293. // Exec executes the query.
  294. func (ssu *SopStageUpdate) Exec(ctx context.Context) error {
  295. _, err := ssu.Save(ctx)
  296. return err
  297. }
  298. // ExecX is like Exec, but panics if an error occurs.
  299. func (ssu *SopStageUpdate) ExecX(ctx context.Context) {
  300. if err := ssu.Exec(ctx); err != nil {
  301. panic(err)
  302. }
  303. }
  304. // defaults sets the default values of the builder before save.
  305. func (ssu *SopStageUpdate) defaults() error {
  306. if _, ok := ssu.mutation.UpdatedAt(); !ok {
  307. if sopstage.UpdateDefaultUpdatedAt == nil {
  308. return fmt.Errorf("ent: uninitialized sopstage.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  309. }
  310. v := sopstage.UpdateDefaultUpdatedAt()
  311. ssu.mutation.SetUpdatedAt(v)
  312. }
  313. return nil
  314. }
  315. // check runs all checks and user-defined validators on the builder.
  316. func (ssu *SopStageUpdate) check() error {
  317. if _, ok := ssu.mutation.SopTaskID(); ssu.mutation.SopTaskCleared() && !ok {
  318. return errors.New(`ent: clearing a required unique edge "SopStage.sop_task"`)
  319. }
  320. return nil
  321. }
  322. func (ssu *SopStageUpdate) sqlSave(ctx context.Context) (n int, err error) {
  323. if err := ssu.check(); err != nil {
  324. return n, err
  325. }
  326. _spec := sqlgraph.NewUpdateSpec(sopstage.Table, sopstage.Columns, sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64))
  327. if ps := ssu.mutation.predicates; len(ps) > 0 {
  328. _spec.Predicate = func(selector *sql.Selector) {
  329. for i := range ps {
  330. ps[i](selector)
  331. }
  332. }
  333. }
  334. if value, ok := ssu.mutation.UpdatedAt(); ok {
  335. _spec.SetField(sopstage.FieldUpdatedAt, field.TypeTime, value)
  336. }
  337. if value, ok := ssu.mutation.Status(); ok {
  338. _spec.SetField(sopstage.FieldStatus, field.TypeUint8, value)
  339. }
  340. if value, ok := ssu.mutation.AddedStatus(); ok {
  341. _spec.AddField(sopstage.FieldStatus, field.TypeUint8, value)
  342. }
  343. if ssu.mutation.StatusCleared() {
  344. _spec.ClearField(sopstage.FieldStatus, field.TypeUint8)
  345. }
  346. if value, ok := ssu.mutation.DeletedAt(); ok {
  347. _spec.SetField(sopstage.FieldDeletedAt, field.TypeTime, value)
  348. }
  349. if ssu.mutation.DeletedAtCleared() {
  350. _spec.ClearField(sopstage.FieldDeletedAt, field.TypeTime)
  351. }
  352. if value, ok := ssu.mutation.Name(); ok {
  353. _spec.SetField(sopstage.FieldName, field.TypeString, value)
  354. }
  355. if value, ok := ssu.mutation.ConditionType(); ok {
  356. _spec.SetField(sopstage.FieldConditionType, field.TypeInt, value)
  357. }
  358. if value, ok := ssu.mutation.AddedConditionType(); ok {
  359. _spec.AddField(sopstage.FieldConditionType, field.TypeInt, value)
  360. }
  361. if value, ok := ssu.mutation.ConditionOperator(); ok {
  362. _spec.SetField(sopstage.FieldConditionOperator, field.TypeInt, value)
  363. }
  364. if value, ok := ssu.mutation.AddedConditionOperator(); ok {
  365. _spec.AddField(sopstage.FieldConditionOperator, field.TypeInt, value)
  366. }
  367. if value, ok := ssu.mutation.ConditionList(); ok {
  368. _spec.SetField(sopstage.FieldConditionList, field.TypeJSON, value)
  369. }
  370. if value, ok := ssu.mutation.AppendedConditionList(); ok {
  371. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  372. sqljson.Append(u, sopstage.FieldConditionList, value)
  373. })
  374. }
  375. if value, ok := ssu.mutation.ActionMessage(); ok {
  376. _spec.SetField(sopstage.FieldActionMessage, field.TypeJSON, value)
  377. }
  378. if value, ok := ssu.mutation.AppendedActionMessage(); ok {
  379. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  380. sqljson.Append(u, sopstage.FieldActionMessage, value)
  381. })
  382. }
  383. if ssu.mutation.ActionMessageCleared() {
  384. _spec.ClearField(sopstage.FieldActionMessage, field.TypeJSON)
  385. }
  386. if value, ok := ssu.mutation.ActionLabel(); ok {
  387. _spec.SetField(sopstage.FieldActionLabel, field.TypeJSON, value)
  388. }
  389. if value, ok := ssu.mutation.AppendedActionLabel(); ok {
  390. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  391. sqljson.Append(u, sopstage.FieldActionLabel, value)
  392. })
  393. }
  394. if ssu.mutation.ActionLabelCleared() {
  395. _spec.ClearField(sopstage.FieldActionLabel, field.TypeJSON)
  396. }
  397. if value, ok := ssu.mutation.IndexSort(); ok {
  398. _spec.SetField(sopstage.FieldIndexSort, field.TypeInt, value)
  399. }
  400. if value, ok := ssu.mutation.AddedIndexSort(); ok {
  401. _spec.AddField(sopstage.FieldIndexSort, field.TypeInt, value)
  402. }
  403. if ssu.mutation.IndexSortCleared() {
  404. _spec.ClearField(sopstage.FieldIndexSort, field.TypeInt)
  405. }
  406. if ssu.mutation.SopTaskCleared() {
  407. edge := &sqlgraph.EdgeSpec{
  408. Rel: sqlgraph.M2O,
  409. Inverse: true,
  410. Table: sopstage.SopTaskTable,
  411. Columns: []string{sopstage.SopTaskColumn},
  412. Bidi: false,
  413. Target: &sqlgraph.EdgeTarget{
  414. IDSpec: sqlgraph.NewFieldSpec(soptask.FieldID, field.TypeUint64),
  415. },
  416. }
  417. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  418. }
  419. if nodes := ssu.mutation.SopTaskIDs(); len(nodes) > 0 {
  420. edge := &sqlgraph.EdgeSpec{
  421. Rel: sqlgraph.M2O,
  422. Inverse: true,
  423. Table: sopstage.SopTaskTable,
  424. Columns: []string{sopstage.SopTaskColumn},
  425. Bidi: false,
  426. Target: &sqlgraph.EdgeTarget{
  427. IDSpec: sqlgraph.NewFieldSpec(soptask.FieldID, field.TypeUint64),
  428. },
  429. }
  430. for _, k := range nodes {
  431. edge.Target.Nodes = append(edge.Target.Nodes, k)
  432. }
  433. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  434. }
  435. if ssu.mutation.StageNodesCleared() {
  436. edge := &sqlgraph.EdgeSpec{
  437. Rel: sqlgraph.O2M,
  438. Inverse: false,
  439. Table: sopstage.StageNodesTable,
  440. Columns: []string{sopstage.StageNodesColumn},
  441. Bidi: false,
  442. Target: &sqlgraph.EdgeTarget{
  443. IDSpec: sqlgraph.NewFieldSpec(sopnode.FieldID, field.TypeUint64),
  444. },
  445. }
  446. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  447. }
  448. if nodes := ssu.mutation.RemovedStageNodesIDs(); len(nodes) > 0 && !ssu.mutation.StageNodesCleared() {
  449. edge := &sqlgraph.EdgeSpec{
  450. Rel: sqlgraph.O2M,
  451. Inverse: false,
  452. Table: sopstage.StageNodesTable,
  453. Columns: []string{sopstage.StageNodesColumn},
  454. Bidi: false,
  455. Target: &sqlgraph.EdgeTarget{
  456. IDSpec: sqlgraph.NewFieldSpec(sopnode.FieldID, field.TypeUint64),
  457. },
  458. }
  459. for _, k := range nodes {
  460. edge.Target.Nodes = append(edge.Target.Nodes, k)
  461. }
  462. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  463. }
  464. if nodes := ssu.mutation.StageNodesIDs(); len(nodes) > 0 {
  465. edge := &sqlgraph.EdgeSpec{
  466. Rel: sqlgraph.O2M,
  467. Inverse: false,
  468. Table: sopstage.StageNodesTable,
  469. Columns: []string{sopstage.StageNodesColumn},
  470. Bidi: false,
  471. Target: &sqlgraph.EdgeTarget{
  472. IDSpec: sqlgraph.NewFieldSpec(sopnode.FieldID, field.TypeUint64),
  473. },
  474. }
  475. for _, k := range nodes {
  476. edge.Target.Nodes = append(edge.Target.Nodes, k)
  477. }
  478. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  479. }
  480. if ssu.mutation.StageMessagesCleared() {
  481. edge := &sqlgraph.EdgeSpec{
  482. Rel: sqlgraph.O2M,
  483. Inverse: false,
  484. Table: sopstage.StageMessagesTable,
  485. Columns: []string{sopstage.StageMessagesColumn},
  486. Bidi: false,
  487. Target: &sqlgraph.EdgeTarget{
  488. IDSpec: sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64),
  489. },
  490. }
  491. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  492. }
  493. if nodes := ssu.mutation.RemovedStageMessagesIDs(); len(nodes) > 0 && !ssu.mutation.StageMessagesCleared() {
  494. edge := &sqlgraph.EdgeSpec{
  495. Rel: sqlgraph.O2M,
  496. Inverse: false,
  497. Table: sopstage.StageMessagesTable,
  498. Columns: []string{sopstage.StageMessagesColumn},
  499. Bidi: false,
  500. Target: &sqlgraph.EdgeTarget{
  501. IDSpec: sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64),
  502. },
  503. }
  504. for _, k := range nodes {
  505. edge.Target.Nodes = append(edge.Target.Nodes, k)
  506. }
  507. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  508. }
  509. if nodes := ssu.mutation.StageMessagesIDs(); len(nodes) > 0 {
  510. edge := &sqlgraph.EdgeSpec{
  511. Rel: sqlgraph.O2M,
  512. Inverse: false,
  513. Table: sopstage.StageMessagesTable,
  514. Columns: []string{sopstage.StageMessagesColumn},
  515. Bidi: false,
  516. Target: &sqlgraph.EdgeTarget{
  517. IDSpec: sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64),
  518. },
  519. }
  520. for _, k := range nodes {
  521. edge.Target.Nodes = append(edge.Target.Nodes, k)
  522. }
  523. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  524. }
  525. if n, err = sqlgraph.UpdateNodes(ctx, ssu.driver, _spec); err != nil {
  526. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  527. err = &NotFoundError{sopstage.Label}
  528. } else if sqlgraph.IsConstraintError(err) {
  529. err = &ConstraintError{msg: err.Error(), wrap: err}
  530. }
  531. return 0, err
  532. }
  533. ssu.mutation.done = true
  534. return n, nil
  535. }
  536. // SopStageUpdateOne is the builder for updating a single SopStage entity.
  537. type SopStageUpdateOne struct {
  538. config
  539. fields []string
  540. hooks []Hook
  541. mutation *SopStageMutation
  542. }
  543. // SetUpdatedAt sets the "updated_at" field.
  544. func (ssuo *SopStageUpdateOne) SetUpdatedAt(t time.Time) *SopStageUpdateOne {
  545. ssuo.mutation.SetUpdatedAt(t)
  546. return ssuo
  547. }
  548. // SetStatus sets the "status" field.
  549. func (ssuo *SopStageUpdateOne) SetStatus(u uint8) *SopStageUpdateOne {
  550. ssuo.mutation.ResetStatus()
  551. ssuo.mutation.SetStatus(u)
  552. return ssuo
  553. }
  554. // SetNillableStatus sets the "status" field if the given value is not nil.
  555. func (ssuo *SopStageUpdateOne) SetNillableStatus(u *uint8) *SopStageUpdateOne {
  556. if u != nil {
  557. ssuo.SetStatus(*u)
  558. }
  559. return ssuo
  560. }
  561. // AddStatus adds u to the "status" field.
  562. func (ssuo *SopStageUpdateOne) AddStatus(u int8) *SopStageUpdateOne {
  563. ssuo.mutation.AddStatus(u)
  564. return ssuo
  565. }
  566. // ClearStatus clears the value of the "status" field.
  567. func (ssuo *SopStageUpdateOne) ClearStatus() *SopStageUpdateOne {
  568. ssuo.mutation.ClearStatus()
  569. return ssuo
  570. }
  571. // SetDeletedAt sets the "deleted_at" field.
  572. func (ssuo *SopStageUpdateOne) SetDeletedAt(t time.Time) *SopStageUpdateOne {
  573. ssuo.mutation.SetDeletedAt(t)
  574. return ssuo
  575. }
  576. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  577. func (ssuo *SopStageUpdateOne) SetNillableDeletedAt(t *time.Time) *SopStageUpdateOne {
  578. if t != nil {
  579. ssuo.SetDeletedAt(*t)
  580. }
  581. return ssuo
  582. }
  583. // ClearDeletedAt clears the value of the "deleted_at" field.
  584. func (ssuo *SopStageUpdateOne) ClearDeletedAt() *SopStageUpdateOne {
  585. ssuo.mutation.ClearDeletedAt()
  586. return ssuo
  587. }
  588. // SetTaskID sets the "task_id" field.
  589. func (ssuo *SopStageUpdateOne) SetTaskID(u uint64) *SopStageUpdateOne {
  590. ssuo.mutation.SetTaskID(u)
  591. return ssuo
  592. }
  593. // SetNillableTaskID sets the "task_id" field if the given value is not nil.
  594. func (ssuo *SopStageUpdateOne) SetNillableTaskID(u *uint64) *SopStageUpdateOne {
  595. if u != nil {
  596. ssuo.SetTaskID(*u)
  597. }
  598. return ssuo
  599. }
  600. // SetName sets the "name" field.
  601. func (ssuo *SopStageUpdateOne) SetName(s string) *SopStageUpdateOne {
  602. ssuo.mutation.SetName(s)
  603. return ssuo
  604. }
  605. // SetNillableName sets the "name" field if the given value is not nil.
  606. func (ssuo *SopStageUpdateOne) SetNillableName(s *string) *SopStageUpdateOne {
  607. if s != nil {
  608. ssuo.SetName(*s)
  609. }
  610. return ssuo
  611. }
  612. // SetConditionType sets the "condition_type" field.
  613. func (ssuo *SopStageUpdateOne) SetConditionType(i int) *SopStageUpdateOne {
  614. ssuo.mutation.ResetConditionType()
  615. ssuo.mutation.SetConditionType(i)
  616. return ssuo
  617. }
  618. // SetNillableConditionType sets the "condition_type" field if the given value is not nil.
  619. func (ssuo *SopStageUpdateOne) SetNillableConditionType(i *int) *SopStageUpdateOne {
  620. if i != nil {
  621. ssuo.SetConditionType(*i)
  622. }
  623. return ssuo
  624. }
  625. // AddConditionType adds i to the "condition_type" field.
  626. func (ssuo *SopStageUpdateOne) AddConditionType(i int) *SopStageUpdateOne {
  627. ssuo.mutation.AddConditionType(i)
  628. return ssuo
  629. }
  630. // SetConditionOperator sets the "condition_operator" field.
  631. func (ssuo *SopStageUpdateOne) SetConditionOperator(i int) *SopStageUpdateOne {
  632. ssuo.mutation.ResetConditionOperator()
  633. ssuo.mutation.SetConditionOperator(i)
  634. return ssuo
  635. }
  636. // SetNillableConditionOperator sets the "condition_operator" field if the given value is not nil.
  637. func (ssuo *SopStageUpdateOne) SetNillableConditionOperator(i *int) *SopStageUpdateOne {
  638. if i != nil {
  639. ssuo.SetConditionOperator(*i)
  640. }
  641. return ssuo
  642. }
  643. // AddConditionOperator adds i to the "condition_operator" field.
  644. func (ssuo *SopStageUpdateOne) AddConditionOperator(i int) *SopStageUpdateOne {
  645. ssuo.mutation.AddConditionOperator(i)
  646. return ssuo
  647. }
  648. // SetConditionList sets the "condition_list" field.
  649. func (ssuo *SopStageUpdateOne) SetConditionList(ct []custom_types.Condition) *SopStageUpdateOne {
  650. ssuo.mutation.SetConditionList(ct)
  651. return ssuo
  652. }
  653. // AppendConditionList appends ct to the "condition_list" field.
  654. func (ssuo *SopStageUpdateOne) AppendConditionList(ct []custom_types.Condition) *SopStageUpdateOne {
  655. ssuo.mutation.AppendConditionList(ct)
  656. return ssuo
  657. }
  658. // SetActionMessage sets the "action_message" field.
  659. func (ssuo *SopStageUpdateOne) SetActionMessage(ct []custom_types.Action) *SopStageUpdateOne {
  660. ssuo.mutation.SetActionMessage(ct)
  661. return ssuo
  662. }
  663. // AppendActionMessage appends ct to the "action_message" field.
  664. func (ssuo *SopStageUpdateOne) AppendActionMessage(ct []custom_types.Action) *SopStageUpdateOne {
  665. ssuo.mutation.AppendActionMessage(ct)
  666. return ssuo
  667. }
  668. // ClearActionMessage clears the value of the "action_message" field.
  669. func (ssuo *SopStageUpdateOne) ClearActionMessage() *SopStageUpdateOne {
  670. ssuo.mutation.ClearActionMessage()
  671. return ssuo
  672. }
  673. // SetActionLabel sets the "action_label" field.
  674. func (ssuo *SopStageUpdateOne) SetActionLabel(u []uint64) *SopStageUpdateOne {
  675. ssuo.mutation.SetActionLabel(u)
  676. return ssuo
  677. }
  678. // AppendActionLabel appends u to the "action_label" field.
  679. func (ssuo *SopStageUpdateOne) AppendActionLabel(u []uint64) *SopStageUpdateOne {
  680. ssuo.mutation.AppendActionLabel(u)
  681. return ssuo
  682. }
  683. // ClearActionLabel clears the value of the "action_label" field.
  684. func (ssuo *SopStageUpdateOne) ClearActionLabel() *SopStageUpdateOne {
  685. ssuo.mutation.ClearActionLabel()
  686. return ssuo
  687. }
  688. // SetIndexSort sets the "index_sort" field.
  689. func (ssuo *SopStageUpdateOne) SetIndexSort(i int) *SopStageUpdateOne {
  690. ssuo.mutation.ResetIndexSort()
  691. ssuo.mutation.SetIndexSort(i)
  692. return ssuo
  693. }
  694. // SetNillableIndexSort sets the "index_sort" field if the given value is not nil.
  695. func (ssuo *SopStageUpdateOne) SetNillableIndexSort(i *int) *SopStageUpdateOne {
  696. if i != nil {
  697. ssuo.SetIndexSort(*i)
  698. }
  699. return ssuo
  700. }
  701. // AddIndexSort adds i to the "index_sort" field.
  702. func (ssuo *SopStageUpdateOne) AddIndexSort(i int) *SopStageUpdateOne {
  703. ssuo.mutation.AddIndexSort(i)
  704. return ssuo
  705. }
  706. // ClearIndexSort clears the value of the "index_sort" field.
  707. func (ssuo *SopStageUpdateOne) ClearIndexSort() *SopStageUpdateOne {
  708. ssuo.mutation.ClearIndexSort()
  709. return ssuo
  710. }
  711. // SetSopTaskID sets the "sop_task" edge to the SopTask entity by ID.
  712. func (ssuo *SopStageUpdateOne) SetSopTaskID(id uint64) *SopStageUpdateOne {
  713. ssuo.mutation.SetSopTaskID(id)
  714. return ssuo
  715. }
  716. // SetSopTask sets the "sop_task" edge to the SopTask entity.
  717. func (ssuo *SopStageUpdateOne) SetSopTask(s *SopTask) *SopStageUpdateOne {
  718. return ssuo.SetSopTaskID(s.ID)
  719. }
  720. // AddStageNodeIDs adds the "stage_nodes" edge to the SopNode entity by IDs.
  721. func (ssuo *SopStageUpdateOne) AddStageNodeIDs(ids ...uint64) *SopStageUpdateOne {
  722. ssuo.mutation.AddStageNodeIDs(ids...)
  723. return ssuo
  724. }
  725. // AddStageNodes adds the "stage_nodes" edges to the SopNode entity.
  726. func (ssuo *SopStageUpdateOne) AddStageNodes(s ...*SopNode) *SopStageUpdateOne {
  727. ids := make([]uint64, len(s))
  728. for i := range s {
  729. ids[i] = s[i].ID
  730. }
  731. return ssuo.AddStageNodeIDs(ids...)
  732. }
  733. // AddStageMessageIDs adds the "stage_messages" edge to the MessageRecords entity by IDs.
  734. func (ssuo *SopStageUpdateOne) AddStageMessageIDs(ids ...uint64) *SopStageUpdateOne {
  735. ssuo.mutation.AddStageMessageIDs(ids...)
  736. return ssuo
  737. }
  738. // AddStageMessages adds the "stage_messages" edges to the MessageRecords entity.
  739. func (ssuo *SopStageUpdateOne) AddStageMessages(m ...*MessageRecords) *SopStageUpdateOne {
  740. ids := make([]uint64, len(m))
  741. for i := range m {
  742. ids[i] = m[i].ID
  743. }
  744. return ssuo.AddStageMessageIDs(ids...)
  745. }
  746. // Mutation returns the SopStageMutation object of the builder.
  747. func (ssuo *SopStageUpdateOne) Mutation() *SopStageMutation {
  748. return ssuo.mutation
  749. }
  750. // ClearSopTask clears the "sop_task" edge to the SopTask entity.
  751. func (ssuo *SopStageUpdateOne) ClearSopTask() *SopStageUpdateOne {
  752. ssuo.mutation.ClearSopTask()
  753. return ssuo
  754. }
  755. // ClearStageNodes clears all "stage_nodes" edges to the SopNode entity.
  756. func (ssuo *SopStageUpdateOne) ClearStageNodes() *SopStageUpdateOne {
  757. ssuo.mutation.ClearStageNodes()
  758. return ssuo
  759. }
  760. // RemoveStageNodeIDs removes the "stage_nodes" edge to SopNode entities by IDs.
  761. func (ssuo *SopStageUpdateOne) RemoveStageNodeIDs(ids ...uint64) *SopStageUpdateOne {
  762. ssuo.mutation.RemoveStageNodeIDs(ids...)
  763. return ssuo
  764. }
  765. // RemoveStageNodes removes "stage_nodes" edges to SopNode entities.
  766. func (ssuo *SopStageUpdateOne) RemoveStageNodes(s ...*SopNode) *SopStageUpdateOne {
  767. ids := make([]uint64, len(s))
  768. for i := range s {
  769. ids[i] = s[i].ID
  770. }
  771. return ssuo.RemoveStageNodeIDs(ids...)
  772. }
  773. // ClearStageMessages clears all "stage_messages" edges to the MessageRecords entity.
  774. func (ssuo *SopStageUpdateOne) ClearStageMessages() *SopStageUpdateOne {
  775. ssuo.mutation.ClearStageMessages()
  776. return ssuo
  777. }
  778. // RemoveStageMessageIDs removes the "stage_messages" edge to MessageRecords entities by IDs.
  779. func (ssuo *SopStageUpdateOne) RemoveStageMessageIDs(ids ...uint64) *SopStageUpdateOne {
  780. ssuo.mutation.RemoveStageMessageIDs(ids...)
  781. return ssuo
  782. }
  783. // RemoveStageMessages removes "stage_messages" edges to MessageRecords entities.
  784. func (ssuo *SopStageUpdateOne) RemoveStageMessages(m ...*MessageRecords) *SopStageUpdateOne {
  785. ids := make([]uint64, len(m))
  786. for i := range m {
  787. ids[i] = m[i].ID
  788. }
  789. return ssuo.RemoveStageMessageIDs(ids...)
  790. }
  791. // Where appends a list predicates to the SopStageUpdate builder.
  792. func (ssuo *SopStageUpdateOne) Where(ps ...predicate.SopStage) *SopStageUpdateOne {
  793. ssuo.mutation.Where(ps...)
  794. return ssuo
  795. }
  796. // Select allows selecting one or more fields (columns) of the returned entity.
  797. // The default is selecting all fields defined in the entity schema.
  798. func (ssuo *SopStageUpdateOne) Select(field string, fields ...string) *SopStageUpdateOne {
  799. ssuo.fields = append([]string{field}, fields...)
  800. return ssuo
  801. }
  802. // Save executes the query and returns the updated SopStage entity.
  803. func (ssuo *SopStageUpdateOne) Save(ctx context.Context) (*SopStage, error) {
  804. if err := ssuo.defaults(); err != nil {
  805. return nil, err
  806. }
  807. return withHooks(ctx, ssuo.sqlSave, ssuo.mutation, ssuo.hooks)
  808. }
  809. // SaveX is like Save, but panics if an error occurs.
  810. func (ssuo *SopStageUpdateOne) SaveX(ctx context.Context) *SopStage {
  811. node, err := ssuo.Save(ctx)
  812. if err != nil {
  813. panic(err)
  814. }
  815. return node
  816. }
  817. // Exec executes the query on the entity.
  818. func (ssuo *SopStageUpdateOne) Exec(ctx context.Context) error {
  819. _, err := ssuo.Save(ctx)
  820. return err
  821. }
  822. // ExecX is like Exec, but panics if an error occurs.
  823. func (ssuo *SopStageUpdateOne) ExecX(ctx context.Context) {
  824. if err := ssuo.Exec(ctx); err != nil {
  825. panic(err)
  826. }
  827. }
  828. // defaults sets the default values of the builder before save.
  829. func (ssuo *SopStageUpdateOne) defaults() error {
  830. if _, ok := ssuo.mutation.UpdatedAt(); !ok {
  831. if sopstage.UpdateDefaultUpdatedAt == nil {
  832. return fmt.Errorf("ent: uninitialized sopstage.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  833. }
  834. v := sopstage.UpdateDefaultUpdatedAt()
  835. ssuo.mutation.SetUpdatedAt(v)
  836. }
  837. return nil
  838. }
  839. // check runs all checks and user-defined validators on the builder.
  840. func (ssuo *SopStageUpdateOne) check() error {
  841. if _, ok := ssuo.mutation.SopTaskID(); ssuo.mutation.SopTaskCleared() && !ok {
  842. return errors.New(`ent: clearing a required unique edge "SopStage.sop_task"`)
  843. }
  844. return nil
  845. }
  846. func (ssuo *SopStageUpdateOne) sqlSave(ctx context.Context) (_node *SopStage, err error) {
  847. if err := ssuo.check(); err != nil {
  848. return _node, err
  849. }
  850. _spec := sqlgraph.NewUpdateSpec(sopstage.Table, sopstage.Columns, sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64))
  851. id, ok := ssuo.mutation.ID()
  852. if !ok {
  853. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "SopStage.id" for update`)}
  854. }
  855. _spec.Node.ID.Value = id
  856. if fields := ssuo.fields; len(fields) > 0 {
  857. _spec.Node.Columns = make([]string, 0, len(fields))
  858. _spec.Node.Columns = append(_spec.Node.Columns, sopstage.FieldID)
  859. for _, f := range fields {
  860. if !sopstage.ValidColumn(f) {
  861. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  862. }
  863. if f != sopstage.FieldID {
  864. _spec.Node.Columns = append(_spec.Node.Columns, f)
  865. }
  866. }
  867. }
  868. if ps := ssuo.mutation.predicates; len(ps) > 0 {
  869. _spec.Predicate = func(selector *sql.Selector) {
  870. for i := range ps {
  871. ps[i](selector)
  872. }
  873. }
  874. }
  875. if value, ok := ssuo.mutation.UpdatedAt(); ok {
  876. _spec.SetField(sopstage.FieldUpdatedAt, field.TypeTime, value)
  877. }
  878. if value, ok := ssuo.mutation.Status(); ok {
  879. _spec.SetField(sopstage.FieldStatus, field.TypeUint8, value)
  880. }
  881. if value, ok := ssuo.mutation.AddedStatus(); ok {
  882. _spec.AddField(sopstage.FieldStatus, field.TypeUint8, value)
  883. }
  884. if ssuo.mutation.StatusCleared() {
  885. _spec.ClearField(sopstage.FieldStatus, field.TypeUint8)
  886. }
  887. if value, ok := ssuo.mutation.DeletedAt(); ok {
  888. _spec.SetField(sopstage.FieldDeletedAt, field.TypeTime, value)
  889. }
  890. if ssuo.mutation.DeletedAtCleared() {
  891. _spec.ClearField(sopstage.FieldDeletedAt, field.TypeTime)
  892. }
  893. if value, ok := ssuo.mutation.Name(); ok {
  894. _spec.SetField(sopstage.FieldName, field.TypeString, value)
  895. }
  896. if value, ok := ssuo.mutation.ConditionType(); ok {
  897. _spec.SetField(sopstage.FieldConditionType, field.TypeInt, value)
  898. }
  899. if value, ok := ssuo.mutation.AddedConditionType(); ok {
  900. _spec.AddField(sopstage.FieldConditionType, field.TypeInt, value)
  901. }
  902. if value, ok := ssuo.mutation.ConditionOperator(); ok {
  903. _spec.SetField(sopstage.FieldConditionOperator, field.TypeInt, value)
  904. }
  905. if value, ok := ssuo.mutation.AddedConditionOperator(); ok {
  906. _spec.AddField(sopstage.FieldConditionOperator, field.TypeInt, value)
  907. }
  908. if value, ok := ssuo.mutation.ConditionList(); ok {
  909. _spec.SetField(sopstage.FieldConditionList, field.TypeJSON, value)
  910. }
  911. if value, ok := ssuo.mutation.AppendedConditionList(); ok {
  912. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  913. sqljson.Append(u, sopstage.FieldConditionList, value)
  914. })
  915. }
  916. if value, ok := ssuo.mutation.ActionMessage(); ok {
  917. _spec.SetField(sopstage.FieldActionMessage, field.TypeJSON, value)
  918. }
  919. if value, ok := ssuo.mutation.AppendedActionMessage(); ok {
  920. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  921. sqljson.Append(u, sopstage.FieldActionMessage, value)
  922. })
  923. }
  924. if ssuo.mutation.ActionMessageCleared() {
  925. _spec.ClearField(sopstage.FieldActionMessage, field.TypeJSON)
  926. }
  927. if value, ok := ssuo.mutation.ActionLabel(); ok {
  928. _spec.SetField(sopstage.FieldActionLabel, field.TypeJSON, value)
  929. }
  930. if value, ok := ssuo.mutation.AppendedActionLabel(); ok {
  931. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  932. sqljson.Append(u, sopstage.FieldActionLabel, value)
  933. })
  934. }
  935. if ssuo.mutation.ActionLabelCleared() {
  936. _spec.ClearField(sopstage.FieldActionLabel, field.TypeJSON)
  937. }
  938. if value, ok := ssuo.mutation.IndexSort(); ok {
  939. _spec.SetField(sopstage.FieldIndexSort, field.TypeInt, value)
  940. }
  941. if value, ok := ssuo.mutation.AddedIndexSort(); ok {
  942. _spec.AddField(sopstage.FieldIndexSort, field.TypeInt, value)
  943. }
  944. if ssuo.mutation.IndexSortCleared() {
  945. _spec.ClearField(sopstage.FieldIndexSort, field.TypeInt)
  946. }
  947. if ssuo.mutation.SopTaskCleared() {
  948. edge := &sqlgraph.EdgeSpec{
  949. Rel: sqlgraph.M2O,
  950. Inverse: true,
  951. Table: sopstage.SopTaskTable,
  952. Columns: []string{sopstage.SopTaskColumn},
  953. Bidi: false,
  954. Target: &sqlgraph.EdgeTarget{
  955. IDSpec: sqlgraph.NewFieldSpec(soptask.FieldID, field.TypeUint64),
  956. },
  957. }
  958. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  959. }
  960. if nodes := ssuo.mutation.SopTaskIDs(); len(nodes) > 0 {
  961. edge := &sqlgraph.EdgeSpec{
  962. Rel: sqlgraph.M2O,
  963. Inverse: true,
  964. Table: sopstage.SopTaskTable,
  965. Columns: []string{sopstage.SopTaskColumn},
  966. Bidi: false,
  967. Target: &sqlgraph.EdgeTarget{
  968. IDSpec: sqlgraph.NewFieldSpec(soptask.FieldID, field.TypeUint64),
  969. },
  970. }
  971. for _, k := range nodes {
  972. edge.Target.Nodes = append(edge.Target.Nodes, k)
  973. }
  974. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  975. }
  976. if ssuo.mutation.StageNodesCleared() {
  977. edge := &sqlgraph.EdgeSpec{
  978. Rel: sqlgraph.O2M,
  979. Inverse: false,
  980. Table: sopstage.StageNodesTable,
  981. Columns: []string{sopstage.StageNodesColumn},
  982. Bidi: false,
  983. Target: &sqlgraph.EdgeTarget{
  984. IDSpec: sqlgraph.NewFieldSpec(sopnode.FieldID, field.TypeUint64),
  985. },
  986. }
  987. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  988. }
  989. if nodes := ssuo.mutation.RemovedStageNodesIDs(); len(nodes) > 0 && !ssuo.mutation.StageNodesCleared() {
  990. edge := &sqlgraph.EdgeSpec{
  991. Rel: sqlgraph.O2M,
  992. Inverse: false,
  993. Table: sopstage.StageNodesTable,
  994. Columns: []string{sopstage.StageNodesColumn},
  995. Bidi: false,
  996. Target: &sqlgraph.EdgeTarget{
  997. IDSpec: sqlgraph.NewFieldSpec(sopnode.FieldID, field.TypeUint64),
  998. },
  999. }
  1000. for _, k := range nodes {
  1001. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1002. }
  1003. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1004. }
  1005. if nodes := ssuo.mutation.StageNodesIDs(); len(nodes) > 0 {
  1006. edge := &sqlgraph.EdgeSpec{
  1007. Rel: sqlgraph.O2M,
  1008. Inverse: false,
  1009. Table: sopstage.StageNodesTable,
  1010. Columns: []string{sopstage.StageNodesColumn},
  1011. Bidi: false,
  1012. Target: &sqlgraph.EdgeTarget{
  1013. IDSpec: sqlgraph.NewFieldSpec(sopnode.FieldID, field.TypeUint64),
  1014. },
  1015. }
  1016. for _, k := range nodes {
  1017. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1018. }
  1019. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1020. }
  1021. if ssuo.mutation.StageMessagesCleared() {
  1022. edge := &sqlgraph.EdgeSpec{
  1023. Rel: sqlgraph.O2M,
  1024. Inverse: false,
  1025. Table: sopstage.StageMessagesTable,
  1026. Columns: []string{sopstage.StageMessagesColumn},
  1027. Bidi: false,
  1028. Target: &sqlgraph.EdgeTarget{
  1029. IDSpec: sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64),
  1030. },
  1031. }
  1032. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1033. }
  1034. if nodes := ssuo.mutation.RemovedStageMessagesIDs(); len(nodes) > 0 && !ssuo.mutation.StageMessagesCleared() {
  1035. edge := &sqlgraph.EdgeSpec{
  1036. Rel: sqlgraph.O2M,
  1037. Inverse: false,
  1038. Table: sopstage.StageMessagesTable,
  1039. Columns: []string{sopstage.StageMessagesColumn},
  1040. Bidi: false,
  1041. Target: &sqlgraph.EdgeTarget{
  1042. IDSpec: sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64),
  1043. },
  1044. }
  1045. for _, k := range nodes {
  1046. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1047. }
  1048. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1049. }
  1050. if nodes := ssuo.mutation.StageMessagesIDs(); len(nodes) > 0 {
  1051. edge := &sqlgraph.EdgeSpec{
  1052. Rel: sqlgraph.O2M,
  1053. Inverse: false,
  1054. Table: sopstage.StageMessagesTable,
  1055. Columns: []string{sopstage.StageMessagesColumn},
  1056. Bidi: false,
  1057. Target: &sqlgraph.EdgeTarget{
  1058. IDSpec: sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64),
  1059. },
  1060. }
  1061. for _, k := range nodes {
  1062. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1063. }
  1064. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1065. }
  1066. _node = &SopStage{config: ssuo.config}
  1067. _spec.Assign = _node.assignValues
  1068. _spec.ScanValues = _node.scanValues
  1069. if err = sqlgraph.UpdateNode(ctx, ssuo.driver, _spec); err != nil {
  1070. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  1071. err = &NotFoundError{sopstage.Label}
  1072. } else if sqlgraph.IsConstraintError(err) {
  1073. err = &ConstraintError{msg: err.Error(), wrap: err}
  1074. }
  1075. return nil, err
  1076. }
  1077. ssuo.mutation.done = true
  1078. return _node, nil
  1079. }