// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "time" "tss-rocks-be/ent/category" "tss-rocks-be/ent/post" "tss-rocks-be/ent/postcontent" "tss-rocks-be/ent/postcontributor" "tss-rocks-be/ent/predicate" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // PostUpdate is the builder for updating Post entities. type PostUpdate struct { config hooks []Hook mutation *PostMutation } // Where appends a list predicates to the PostUpdate builder. func (pu *PostUpdate) Where(ps ...predicate.Post) *PostUpdate { pu.mutation.Where(ps...) return pu } // SetStatus sets the "status" field. func (pu *PostUpdate) SetStatus(po post.Status) *PostUpdate { pu.mutation.SetStatus(po) return pu } // SetNillableStatus sets the "status" field if the given value is not nil. func (pu *PostUpdate) SetNillableStatus(po *post.Status) *PostUpdate { if po != nil { pu.SetStatus(*po) } return pu } // SetSlug sets the "slug" field. func (pu *PostUpdate) SetSlug(s string) *PostUpdate { pu.mutation.SetSlug(s) return pu } // SetNillableSlug sets the "slug" field if the given value is not nil. func (pu *PostUpdate) SetNillableSlug(s *string) *PostUpdate { if s != nil { pu.SetSlug(*s) } return pu } // SetCreatedAt sets the "created_at" field. func (pu *PostUpdate) SetCreatedAt(t time.Time) *PostUpdate { pu.mutation.SetCreatedAt(t) return pu } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (pu *PostUpdate) SetNillableCreatedAt(t *time.Time) *PostUpdate { if t != nil { pu.SetCreatedAt(*t) } return pu } // SetUpdatedAt sets the "updated_at" field. func (pu *PostUpdate) SetUpdatedAt(t time.Time) *PostUpdate { pu.mutation.SetUpdatedAt(t) return pu } // AddContentIDs adds the "contents" edge to the PostContent entity by IDs. func (pu *PostUpdate) AddContentIDs(ids ...int) *PostUpdate { pu.mutation.AddContentIDs(ids...) return pu } // AddContents adds the "contents" edges to the PostContent entity. func (pu *PostUpdate) AddContents(p ...*PostContent) *PostUpdate { ids := make([]int, len(p)) for i := range p { ids[i] = p[i].ID } return pu.AddContentIDs(ids...) } // AddContributorIDs adds the "contributors" edge to the PostContributor entity by IDs. func (pu *PostUpdate) AddContributorIDs(ids ...int) *PostUpdate { pu.mutation.AddContributorIDs(ids...) return pu } // AddContributors adds the "contributors" edges to the PostContributor entity. func (pu *PostUpdate) AddContributors(p ...*PostContributor) *PostUpdate { ids := make([]int, len(p)) for i := range p { ids[i] = p[i].ID } return pu.AddContributorIDs(ids...) } // AddCategoryIDs adds the "categories" edge to the Category entity by IDs. func (pu *PostUpdate) AddCategoryIDs(ids ...int) *PostUpdate { pu.mutation.AddCategoryIDs(ids...) return pu } // AddCategories adds the "categories" edges to the Category entity. func (pu *PostUpdate) AddCategories(c ...*Category) *PostUpdate { ids := make([]int, len(c)) for i := range c { ids[i] = c[i].ID } return pu.AddCategoryIDs(ids...) } // Mutation returns the PostMutation object of the builder. func (pu *PostUpdate) Mutation() *PostMutation { return pu.mutation } // ClearContents clears all "contents" edges to the PostContent entity. func (pu *PostUpdate) ClearContents() *PostUpdate { pu.mutation.ClearContents() return pu } // RemoveContentIDs removes the "contents" edge to PostContent entities by IDs. func (pu *PostUpdate) RemoveContentIDs(ids ...int) *PostUpdate { pu.mutation.RemoveContentIDs(ids...) return pu } // RemoveContents removes "contents" edges to PostContent entities. func (pu *PostUpdate) RemoveContents(p ...*PostContent) *PostUpdate { ids := make([]int, len(p)) for i := range p { ids[i] = p[i].ID } return pu.RemoveContentIDs(ids...) } // ClearContributors clears all "contributors" edges to the PostContributor entity. func (pu *PostUpdate) ClearContributors() *PostUpdate { pu.mutation.ClearContributors() return pu } // RemoveContributorIDs removes the "contributors" edge to PostContributor entities by IDs. func (pu *PostUpdate) RemoveContributorIDs(ids ...int) *PostUpdate { pu.mutation.RemoveContributorIDs(ids...) return pu } // RemoveContributors removes "contributors" edges to PostContributor entities. func (pu *PostUpdate) RemoveContributors(p ...*PostContributor) *PostUpdate { ids := make([]int, len(p)) for i := range p { ids[i] = p[i].ID } return pu.RemoveContributorIDs(ids...) } // ClearCategories clears all "categories" edges to the Category entity. func (pu *PostUpdate) ClearCategories() *PostUpdate { pu.mutation.ClearCategories() return pu } // RemoveCategoryIDs removes the "categories" edge to Category entities by IDs. func (pu *PostUpdate) RemoveCategoryIDs(ids ...int) *PostUpdate { pu.mutation.RemoveCategoryIDs(ids...) return pu } // RemoveCategories removes "categories" edges to Category entities. func (pu *PostUpdate) RemoveCategories(c ...*Category) *PostUpdate { ids := make([]int, len(c)) for i := range c { ids[i] = c[i].ID } return pu.RemoveCategoryIDs(ids...) } // Save executes the query and returns the number of nodes affected by the update operation. func (pu *PostUpdate) Save(ctx context.Context) (int, error) { pu.defaults() return withHooks(ctx, pu.sqlSave, pu.mutation, pu.hooks) } // SaveX is like Save, but panics if an error occurs. func (pu *PostUpdate) SaveX(ctx context.Context) int { affected, err := pu.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (pu *PostUpdate) Exec(ctx context.Context) error { _, err := pu.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (pu *PostUpdate) ExecX(ctx context.Context) { if err := pu.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. func (pu *PostUpdate) defaults() { if _, ok := pu.mutation.UpdatedAt(); !ok { v := post.UpdateDefaultUpdatedAt() pu.mutation.SetUpdatedAt(v) } } // check runs all checks and user-defined validators on the builder. func (pu *PostUpdate) check() error { if v, ok := pu.mutation.Status(); ok { if err := post.StatusValidator(v); err != nil { return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Post.status": %w`, err)} } } if v, ok := pu.mutation.Slug(); ok { if err := post.SlugValidator(v); err != nil { return &ValidationError{Name: "slug", err: fmt.Errorf(`ent: validator failed for field "Post.slug": %w`, err)} } } return nil } func (pu *PostUpdate) sqlSave(ctx context.Context) (n int, err error) { if err := pu.check(); err != nil { return n, err } _spec := sqlgraph.NewUpdateSpec(post.Table, post.Columns, sqlgraph.NewFieldSpec(post.FieldID, field.TypeInt)) if ps := pu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := pu.mutation.Status(); ok { _spec.SetField(post.FieldStatus, field.TypeEnum, value) } if value, ok := pu.mutation.Slug(); ok { _spec.SetField(post.FieldSlug, field.TypeString, value) } if value, ok := pu.mutation.CreatedAt(); ok { _spec.SetField(post.FieldCreatedAt, field.TypeTime, value) } if value, ok := pu.mutation.UpdatedAt(); ok { _spec.SetField(post.FieldUpdatedAt, field.TypeTime, value) } if pu.mutation.ContentsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: post.ContentsTable, Columns: []string{post.ContentsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(postcontent.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := pu.mutation.RemovedContentsIDs(); len(nodes) > 0 && !pu.mutation.ContentsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: post.ContentsTable, Columns: []string{post.ContentsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(postcontent.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := pu.mutation.ContentsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: post.ContentsTable, Columns: []string{post.ContentsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(postcontent.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } if pu.mutation.ContributorsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: post.ContributorsTable, Columns: []string{post.ContributorsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(postcontributor.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := pu.mutation.RemovedContributorsIDs(); len(nodes) > 0 && !pu.mutation.ContributorsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: post.ContributorsTable, Columns: []string{post.ContributorsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(postcontributor.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := pu.mutation.ContributorsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: post.ContributorsTable, Columns: []string{post.ContributorsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(postcontributor.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } if pu.mutation.CategoriesCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: true, Table: post.CategoriesTable, Columns: post.CategoriesPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(category.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := pu.mutation.RemovedCategoriesIDs(); len(nodes) > 0 && !pu.mutation.CategoriesCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: true, Table: post.CategoriesTable, Columns: post.CategoriesPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(category.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := pu.mutation.CategoriesIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: true, Table: post.CategoriesTable, Columns: post.CategoriesPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(category.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } if n, err = sqlgraph.UpdateNodes(ctx, pu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{post.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } pu.mutation.done = true return n, nil } // PostUpdateOne is the builder for updating a single Post entity. type PostUpdateOne struct { config fields []string hooks []Hook mutation *PostMutation } // SetStatus sets the "status" field. func (puo *PostUpdateOne) SetStatus(po post.Status) *PostUpdateOne { puo.mutation.SetStatus(po) return puo } // SetNillableStatus sets the "status" field if the given value is not nil. func (puo *PostUpdateOne) SetNillableStatus(po *post.Status) *PostUpdateOne { if po != nil { puo.SetStatus(*po) } return puo } // SetSlug sets the "slug" field. func (puo *PostUpdateOne) SetSlug(s string) *PostUpdateOne { puo.mutation.SetSlug(s) return puo } // SetNillableSlug sets the "slug" field if the given value is not nil. func (puo *PostUpdateOne) SetNillableSlug(s *string) *PostUpdateOne { if s != nil { puo.SetSlug(*s) } return puo } // SetCreatedAt sets the "created_at" field. func (puo *PostUpdateOne) SetCreatedAt(t time.Time) *PostUpdateOne { puo.mutation.SetCreatedAt(t) return puo } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (puo *PostUpdateOne) SetNillableCreatedAt(t *time.Time) *PostUpdateOne { if t != nil { puo.SetCreatedAt(*t) } return puo } // SetUpdatedAt sets the "updated_at" field. func (puo *PostUpdateOne) SetUpdatedAt(t time.Time) *PostUpdateOne { puo.mutation.SetUpdatedAt(t) return puo } // AddContentIDs adds the "contents" edge to the PostContent entity by IDs. func (puo *PostUpdateOne) AddContentIDs(ids ...int) *PostUpdateOne { puo.mutation.AddContentIDs(ids...) return puo } // AddContents adds the "contents" edges to the PostContent entity. func (puo *PostUpdateOne) AddContents(p ...*PostContent) *PostUpdateOne { ids := make([]int, len(p)) for i := range p { ids[i] = p[i].ID } return puo.AddContentIDs(ids...) } // AddContributorIDs adds the "contributors" edge to the PostContributor entity by IDs. func (puo *PostUpdateOne) AddContributorIDs(ids ...int) *PostUpdateOne { puo.mutation.AddContributorIDs(ids...) return puo } // AddContributors adds the "contributors" edges to the PostContributor entity. func (puo *PostUpdateOne) AddContributors(p ...*PostContributor) *PostUpdateOne { ids := make([]int, len(p)) for i := range p { ids[i] = p[i].ID } return puo.AddContributorIDs(ids...) } // AddCategoryIDs adds the "categories" edge to the Category entity by IDs. func (puo *PostUpdateOne) AddCategoryIDs(ids ...int) *PostUpdateOne { puo.mutation.AddCategoryIDs(ids...) return puo } // AddCategories adds the "categories" edges to the Category entity. func (puo *PostUpdateOne) AddCategories(c ...*Category) *PostUpdateOne { ids := make([]int, len(c)) for i := range c { ids[i] = c[i].ID } return puo.AddCategoryIDs(ids...) } // Mutation returns the PostMutation object of the builder. func (puo *PostUpdateOne) Mutation() *PostMutation { return puo.mutation } // ClearContents clears all "contents" edges to the PostContent entity. func (puo *PostUpdateOne) ClearContents() *PostUpdateOne { puo.mutation.ClearContents() return puo } // RemoveContentIDs removes the "contents" edge to PostContent entities by IDs. func (puo *PostUpdateOne) RemoveContentIDs(ids ...int) *PostUpdateOne { puo.mutation.RemoveContentIDs(ids...) return puo } // RemoveContents removes "contents" edges to PostContent entities. func (puo *PostUpdateOne) RemoveContents(p ...*PostContent) *PostUpdateOne { ids := make([]int, len(p)) for i := range p { ids[i] = p[i].ID } return puo.RemoveContentIDs(ids...) } // ClearContributors clears all "contributors" edges to the PostContributor entity. func (puo *PostUpdateOne) ClearContributors() *PostUpdateOne { puo.mutation.ClearContributors() return puo } // RemoveContributorIDs removes the "contributors" edge to PostContributor entities by IDs. func (puo *PostUpdateOne) RemoveContributorIDs(ids ...int) *PostUpdateOne { puo.mutation.RemoveContributorIDs(ids...) return puo } // RemoveContributors removes "contributors" edges to PostContributor entities. func (puo *PostUpdateOne) RemoveContributors(p ...*PostContributor) *PostUpdateOne { ids := make([]int, len(p)) for i := range p { ids[i] = p[i].ID } return puo.RemoveContributorIDs(ids...) } // ClearCategories clears all "categories" edges to the Category entity. func (puo *PostUpdateOne) ClearCategories() *PostUpdateOne { puo.mutation.ClearCategories() return puo } // RemoveCategoryIDs removes the "categories" edge to Category entities by IDs. func (puo *PostUpdateOne) RemoveCategoryIDs(ids ...int) *PostUpdateOne { puo.mutation.RemoveCategoryIDs(ids...) return puo } // RemoveCategories removes "categories" edges to Category entities. func (puo *PostUpdateOne) RemoveCategories(c ...*Category) *PostUpdateOne { ids := make([]int, len(c)) for i := range c { ids[i] = c[i].ID } return puo.RemoveCategoryIDs(ids...) } // Where appends a list predicates to the PostUpdate builder. func (puo *PostUpdateOne) Where(ps ...predicate.Post) *PostUpdateOne { puo.mutation.Where(ps...) return puo } // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (puo *PostUpdateOne) Select(field string, fields ...string) *PostUpdateOne { puo.fields = append([]string{field}, fields...) return puo } // Save executes the query and returns the updated Post entity. func (puo *PostUpdateOne) Save(ctx context.Context) (*Post, error) { puo.defaults() return withHooks(ctx, puo.sqlSave, puo.mutation, puo.hooks) } // SaveX is like Save, but panics if an error occurs. func (puo *PostUpdateOne) SaveX(ctx context.Context) *Post { node, err := puo.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (puo *PostUpdateOne) Exec(ctx context.Context) error { _, err := puo.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (puo *PostUpdateOne) ExecX(ctx context.Context) { if err := puo.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. func (puo *PostUpdateOne) defaults() { if _, ok := puo.mutation.UpdatedAt(); !ok { v := post.UpdateDefaultUpdatedAt() puo.mutation.SetUpdatedAt(v) } } // check runs all checks and user-defined validators on the builder. func (puo *PostUpdateOne) check() error { if v, ok := puo.mutation.Status(); ok { if err := post.StatusValidator(v); err != nil { return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Post.status": %w`, err)} } } if v, ok := puo.mutation.Slug(); ok { if err := post.SlugValidator(v); err != nil { return &ValidationError{Name: "slug", err: fmt.Errorf(`ent: validator failed for field "Post.slug": %w`, err)} } } return nil } func (puo *PostUpdateOne) sqlSave(ctx context.Context) (_node *Post, err error) { if err := puo.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(post.Table, post.Columns, sqlgraph.NewFieldSpec(post.FieldID, field.TypeInt)) id, ok := puo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Post.id" for update`)} } _spec.Node.ID.Value = id if fields := puo.fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, post.FieldID) for _, f := range fields { if !post.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != post.FieldID { _spec.Node.Columns = append(_spec.Node.Columns, f) } } } if ps := puo.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := puo.mutation.Status(); ok { _spec.SetField(post.FieldStatus, field.TypeEnum, value) } if value, ok := puo.mutation.Slug(); ok { _spec.SetField(post.FieldSlug, field.TypeString, value) } if value, ok := puo.mutation.CreatedAt(); ok { _spec.SetField(post.FieldCreatedAt, field.TypeTime, value) } if value, ok := puo.mutation.UpdatedAt(); ok { _spec.SetField(post.FieldUpdatedAt, field.TypeTime, value) } if puo.mutation.ContentsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: post.ContentsTable, Columns: []string{post.ContentsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(postcontent.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := puo.mutation.RemovedContentsIDs(); len(nodes) > 0 && !puo.mutation.ContentsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: post.ContentsTable, Columns: []string{post.ContentsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(postcontent.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := puo.mutation.ContentsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: post.ContentsTable, Columns: []string{post.ContentsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(postcontent.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } if puo.mutation.ContributorsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: post.ContributorsTable, Columns: []string{post.ContributorsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(postcontributor.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := puo.mutation.RemovedContributorsIDs(); len(nodes) > 0 && !puo.mutation.ContributorsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: post.ContributorsTable, Columns: []string{post.ContributorsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(postcontributor.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := puo.mutation.ContributorsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: post.ContributorsTable, Columns: []string{post.ContributorsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(postcontributor.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } if puo.mutation.CategoriesCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: true, Table: post.CategoriesTable, Columns: post.CategoriesPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(category.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := puo.mutation.RemovedCategoriesIDs(); len(nodes) > 0 && !puo.mutation.CategoriesCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: true, Table: post.CategoriesTable, Columns: post.CategoriesPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(category.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := puo.mutation.CategoriesIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: true, Table: post.CategoriesTable, Columns: post.CategoriesPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(category.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } _node = &Post{config: puo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues if err = sqlgraph.UpdateNode(ctx, puo.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{post.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } puo.mutation.done = true return _node, nil }