labelrelationship_update.go 20 KB

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