[feature/backend] add categories param in posts
This commit is contained in:
parent
958e3c2886
commit
be8bf22017
21 changed files with 448 additions and 281 deletions
|
@ -109,23 +109,19 @@ func (pu *PostUpdate) AddContributors(p ...*PostContributor) *PostUpdate {
|
|||
return pu.AddContributorIDs(ids...)
|
||||
}
|
||||
|
||||
// SetCategoryID sets the "category" edge to the Category entity by ID.
|
||||
func (pu *PostUpdate) SetCategoryID(id int) *PostUpdate {
|
||||
pu.mutation.SetCategoryID(id)
|
||||
// AddCategoryIDs adds the "categories" edge to the Category entity by IDs.
|
||||
func (pu *PostUpdate) AddCategoryIDs(ids ...int) *PostUpdate {
|
||||
pu.mutation.AddCategoryIDs(ids...)
|
||||
return pu
|
||||
}
|
||||
|
||||
// SetNillableCategoryID sets the "category" edge to the Category entity by ID if the given value is not nil.
|
||||
func (pu *PostUpdate) SetNillableCategoryID(id *int) *PostUpdate {
|
||||
if id != nil {
|
||||
pu = pu.SetCategoryID(*id)
|
||||
// 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
|
||||
}
|
||||
|
||||
// SetCategory sets the "category" edge to the Category entity.
|
||||
func (pu *PostUpdate) SetCategory(c *Category) *PostUpdate {
|
||||
return pu.SetCategoryID(c.ID)
|
||||
return pu.AddCategoryIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the PostMutation object of the builder.
|
||||
|
@ -175,12 +171,27 @@ func (pu *PostUpdate) RemoveContributors(p ...*PostContributor) *PostUpdate {
|
|||
return pu.RemoveContributorIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearCategory clears the "category" edge to the Category entity.
|
||||
func (pu *PostUpdate) ClearCategory() *PostUpdate {
|
||||
pu.mutation.ClearCategory()
|
||||
// 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()
|
||||
|
@ -346,12 +357,12 @@ func (pu *PostUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if pu.mutation.CategoryCleared() {
|
||||
if pu.mutation.CategoriesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: true,
|
||||
Table: post.CategoryTable,
|
||||
Columns: []string{post.CategoryColumn},
|
||||
Table: post.CategoriesTable,
|
||||
Columns: post.CategoriesPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(category.FieldID, field.TypeInt),
|
||||
|
@ -359,12 +370,28 @@ func (pu *PostUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := pu.mutation.CategoryIDs(); len(nodes) > 0 {
|
||||
if nodes := pu.mutation.RemovedCategoriesIDs(); len(nodes) > 0 && !pu.mutation.CategoriesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: true,
|
||||
Table: post.CategoryTable,
|
||||
Columns: []string{post.CategoryColumn},
|
||||
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),
|
||||
|
@ -473,23 +500,19 @@ func (puo *PostUpdateOne) AddContributors(p ...*PostContributor) *PostUpdateOne
|
|||
return puo.AddContributorIDs(ids...)
|
||||
}
|
||||
|
||||
// SetCategoryID sets the "category" edge to the Category entity by ID.
|
||||
func (puo *PostUpdateOne) SetCategoryID(id int) *PostUpdateOne {
|
||||
puo.mutation.SetCategoryID(id)
|
||||
// AddCategoryIDs adds the "categories" edge to the Category entity by IDs.
|
||||
func (puo *PostUpdateOne) AddCategoryIDs(ids ...int) *PostUpdateOne {
|
||||
puo.mutation.AddCategoryIDs(ids...)
|
||||
return puo
|
||||
}
|
||||
|
||||
// SetNillableCategoryID sets the "category" edge to the Category entity by ID if the given value is not nil.
|
||||
func (puo *PostUpdateOne) SetNillableCategoryID(id *int) *PostUpdateOne {
|
||||
if id != nil {
|
||||
puo = puo.SetCategoryID(*id)
|
||||
// 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
|
||||
}
|
||||
|
||||
// SetCategory sets the "category" edge to the Category entity.
|
||||
func (puo *PostUpdateOne) SetCategory(c *Category) *PostUpdateOne {
|
||||
return puo.SetCategoryID(c.ID)
|
||||
return puo.AddCategoryIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the PostMutation object of the builder.
|
||||
|
@ -539,12 +562,27 @@ func (puo *PostUpdateOne) RemoveContributors(p ...*PostContributor) *PostUpdateO
|
|||
return puo.RemoveContributorIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearCategory clears the "category" edge to the Category entity.
|
||||
func (puo *PostUpdateOne) ClearCategory() *PostUpdateOne {
|
||||
puo.mutation.ClearCategory()
|
||||
// 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...)
|
||||
|
@ -740,12 +778,12 @@ func (puo *PostUpdateOne) sqlSave(ctx context.Context) (_node *Post, err error)
|
|||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if puo.mutation.CategoryCleared() {
|
||||
if puo.mutation.CategoriesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: true,
|
||||
Table: post.CategoryTable,
|
||||
Columns: []string{post.CategoryColumn},
|
||||
Table: post.CategoriesTable,
|
||||
Columns: post.CategoriesPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(category.FieldID, field.TypeInt),
|
||||
|
@ -753,12 +791,28 @@ func (puo *PostUpdateOne) sqlSave(ctx context.Context) (_node *Post, err error)
|
|||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := puo.mutation.CategoryIDs(); len(nodes) > 0 {
|
||||
if nodes := puo.mutation.RemovedCategoriesIDs(); len(nodes) > 0 && !puo.mutation.CategoriesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: true,
|
||||
Table: post.CategoryTable,
|
||||
Columns: []string{post.CategoryColumn},
|
||||
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),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue