messagerecords_update.go 36 KB

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