sopstage_update.go 40 KB

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