labelrelationship_update.go 19 KB

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