mirror of
https://github.com/hay-kot/homebox.git
synced 2024-12-22 14:56:31 +00:00
1126 lines
30 KiB
Go
1126 lines
30 KiB
Go
|
// Code generated by ent, DO NOT EDIT.
|
||
|
|
||
|
package ent
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"errors"
|
||
|
"fmt"
|
||
|
"time"
|
||
|
|
||
|
"entgo.io/ent/dialect/sql"
|
||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||
|
"entgo.io/ent/schema/field"
|
||
|
"github.com/google/uuid"
|
||
|
"github.com/hay-kot/content/backend/ent/group"
|
||
|
"github.com/hay-kot/content/backend/ent/item"
|
||
|
"github.com/hay-kot/content/backend/ent/label"
|
||
|
"github.com/hay-kot/content/backend/ent/location"
|
||
|
"github.com/hay-kot/content/backend/ent/predicate"
|
||
|
"github.com/hay-kot/content/backend/ent/user"
|
||
|
)
|
||
|
|
||
|
// GroupUpdate is the builder for updating Group entities.
|
||
|
type GroupUpdate struct {
|
||
|
config
|
||
|
hooks []Hook
|
||
|
mutation *GroupMutation
|
||
|
}
|
||
|
|
||
|
// Where appends a list predicates to the GroupUpdate builder.
|
||
|
func (gu *GroupUpdate) Where(ps ...predicate.Group) *GroupUpdate {
|
||
|
gu.mutation.Where(ps...)
|
||
|
return gu
|
||
|
}
|
||
|
|
||
|
// SetUpdatedAt sets the "updated_at" field.
|
||
|
func (gu *GroupUpdate) SetUpdatedAt(t time.Time) *GroupUpdate {
|
||
|
gu.mutation.SetUpdatedAt(t)
|
||
|
return gu
|
||
|
}
|
||
|
|
||
|
// SetName sets the "name" field.
|
||
|
func (gu *GroupUpdate) SetName(s string) *GroupUpdate {
|
||
|
gu.mutation.SetName(s)
|
||
|
return gu
|
||
|
}
|
||
|
|
||
|
// SetCurrency sets the "currency" field.
|
||
|
func (gu *GroupUpdate) SetCurrency(gr group.Currency) *GroupUpdate {
|
||
|
gu.mutation.SetCurrency(gr)
|
||
|
return gu
|
||
|
}
|
||
|
|
||
|
// SetNillableCurrency sets the "currency" field if the given value is not nil.
|
||
|
func (gu *GroupUpdate) SetNillableCurrency(gr *group.Currency) *GroupUpdate {
|
||
|
if gr != nil {
|
||
|
gu.SetCurrency(*gr)
|
||
|
}
|
||
|
return gu
|
||
|
}
|
||
|
|
||
|
// AddUserIDs adds the "users" edge to the User entity by IDs.
|
||
|
func (gu *GroupUpdate) AddUserIDs(ids ...uuid.UUID) *GroupUpdate {
|
||
|
gu.mutation.AddUserIDs(ids...)
|
||
|
return gu
|
||
|
}
|
||
|
|
||
|
// AddUsers adds the "users" edges to the User entity.
|
||
|
func (gu *GroupUpdate) AddUsers(u ...*User) *GroupUpdate {
|
||
|
ids := make([]uuid.UUID, len(u))
|
||
|
for i := range u {
|
||
|
ids[i] = u[i].ID
|
||
|
}
|
||
|
return gu.AddUserIDs(ids...)
|
||
|
}
|
||
|
|
||
|
// AddLocationIDs adds the "locations" edge to the Location entity by IDs.
|
||
|
func (gu *GroupUpdate) AddLocationIDs(ids ...uuid.UUID) *GroupUpdate {
|
||
|
gu.mutation.AddLocationIDs(ids...)
|
||
|
return gu
|
||
|
}
|
||
|
|
||
|
// AddLocations adds the "locations" edges to the Location entity.
|
||
|
func (gu *GroupUpdate) AddLocations(l ...*Location) *GroupUpdate {
|
||
|
ids := make([]uuid.UUID, len(l))
|
||
|
for i := range l {
|
||
|
ids[i] = l[i].ID
|
||
|
}
|
||
|
return gu.AddLocationIDs(ids...)
|
||
|
}
|
||
|
|
||
|
// AddItemIDs adds the "items" edge to the Item entity by IDs.
|
||
|
func (gu *GroupUpdate) AddItemIDs(ids ...uuid.UUID) *GroupUpdate {
|
||
|
gu.mutation.AddItemIDs(ids...)
|
||
|
return gu
|
||
|
}
|
||
|
|
||
|
// AddItems adds the "items" edges to the Item entity.
|
||
|
func (gu *GroupUpdate) AddItems(i ...*Item) *GroupUpdate {
|
||
|
ids := make([]uuid.UUID, len(i))
|
||
|
for j := range i {
|
||
|
ids[j] = i[j].ID
|
||
|
}
|
||
|
return gu.AddItemIDs(ids...)
|
||
|
}
|
||
|
|
||
|
// AddLabelIDs adds the "labels" edge to the Label entity by IDs.
|
||
|
func (gu *GroupUpdate) AddLabelIDs(ids ...uuid.UUID) *GroupUpdate {
|
||
|
gu.mutation.AddLabelIDs(ids...)
|
||
|
return gu
|
||
|
}
|
||
|
|
||
|
// AddLabels adds the "labels" edges to the Label entity.
|
||
|
func (gu *GroupUpdate) AddLabels(l ...*Label) *GroupUpdate {
|
||
|
ids := make([]uuid.UUID, len(l))
|
||
|
for i := range l {
|
||
|
ids[i] = l[i].ID
|
||
|
}
|
||
|
return gu.AddLabelIDs(ids...)
|
||
|
}
|
||
|
|
||
|
// Mutation returns the GroupMutation object of the builder.
|
||
|
func (gu *GroupUpdate) Mutation() *GroupMutation {
|
||
|
return gu.mutation
|
||
|
}
|
||
|
|
||
|
// ClearUsers clears all "users" edges to the User entity.
|
||
|
func (gu *GroupUpdate) ClearUsers() *GroupUpdate {
|
||
|
gu.mutation.ClearUsers()
|
||
|
return gu
|
||
|
}
|
||
|
|
||
|
// RemoveUserIDs removes the "users" edge to User entities by IDs.
|
||
|
func (gu *GroupUpdate) RemoveUserIDs(ids ...uuid.UUID) *GroupUpdate {
|
||
|
gu.mutation.RemoveUserIDs(ids...)
|
||
|
return gu
|
||
|
}
|
||
|
|
||
|
// RemoveUsers removes "users" edges to User entities.
|
||
|
func (gu *GroupUpdate) RemoveUsers(u ...*User) *GroupUpdate {
|
||
|
ids := make([]uuid.UUID, len(u))
|
||
|
for i := range u {
|
||
|
ids[i] = u[i].ID
|
||
|
}
|
||
|
return gu.RemoveUserIDs(ids...)
|
||
|
}
|
||
|
|
||
|
// ClearLocations clears all "locations" edges to the Location entity.
|
||
|
func (gu *GroupUpdate) ClearLocations() *GroupUpdate {
|
||
|
gu.mutation.ClearLocations()
|
||
|
return gu
|
||
|
}
|
||
|
|
||
|
// RemoveLocationIDs removes the "locations" edge to Location entities by IDs.
|
||
|
func (gu *GroupUpdate) RemoveLocationIDs(ids ...uuid.UUID) *GroupUpdate {
|
||
|
gu.mutation.RemoveLocationIDs(ids...)
|
||
|
return gu
|
||
|
}
|
||
|
|
||
|
// RemoveLocations removes "locations" edges to Location entities.
|
||
|
func (gu *GroupUpdate) RemoveLocations(l ...*Location) *GroupUpdate {
|
||
|
ids := make([]uuid.UUID, len(l))
|
||
|
for i := range l {
|
||
|
ids[i] = l[i].ID
|
||
|
}
|
||
|
return gu.RemoveLocationIDs(ids...)
|
||
|
}
|
||
|
|
||
|
// ClearItems clears all "items" edges to the Item entity.
|
||
|
func (gu *GroupUpdate) ClearItems() *GroupUpdate {
|
||
|
gu.mutation.ClearItems()
|
||
|
return gu
|
||
|
}
|
||
|
|
||
|
// RemoveItemIDs removes the "items" edge to Item entities by IDs.
|
||
|
func (gu *GroupUpdate) RemoveItemIDs(ids ...uuid.UUID) *GroupUpdate {
|
||
|
gu.mutation.RemoveItemIDs(ids...)
|
||
|
return gu
|
||
|
}
|
||
|
|
||
|
// RemoveItems removes "items" edges to Item entities.
|
||
|
func (gu *GroupUpdate) RemoveItems(i ...*Item) *GroupUpdate {
|
||
|
ids := make([]uuid.UUID, len(i))
|
||
|
for j := range i {
|
||
|
ids[j] = i[j].ID
|
||
|
}
|
||
|
return gu.RemoveItemIDs(ids...)
|
||
|
}
|
||
|
|
||
|
// ClearLabels clears all "labels" edges to the Label entity.
|
||
|
func (gu *GroupUpdate) ClearLabels() *GroupUpdate {
|
||
|
gu.mutation.ClearLabels()
|
||
|
return gu
|
||
|
}
|
||
|
|
||
|
// RemoveLabelIDs removes the "labels" edge to Label entities by IDs.
|
||
|
func (gu *GroupUpdate) RemoveLabelIDs(ids ...uuid.UUID) *GroupUpdate {
|
||
|
gu.mutation.RemoveLabelIDs(ids...)
|
||
|
return gu
|
||
|
}
|
||
|
|
||
|
// RemoveLabels removes "labels" edges to Label entities.
|
||
|
func (gu *GroupUpdate) RemoveLabels(l ...*Label) *GroupUpdate {
|
||
|
ids := make([]uuid.UUID, len(l))
|
||
|
for i := range l {
|
||
|
ids[i] = l[i].ID
|
||
|
}
|
||
|
return gu.RemoveLabelIDs(ids...)
|
||
|
}
|
||
|
|
||
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||
|
func (gu *GroupUpdate) Save(ctx context.Context) (int, error) {
|
||
|
var (
|
||
|
err error
|
||
|
affected int
|
||
|
)
|
||
|
gu.defaults()
|
||
|
if len(gu.hooks) == 0 {
|
||
|
if err = gu.check(); err != nil {
|
||
|
return 0, err
|
||
|
}
|
||
|
affected, err = gu.sqlSave(ctx)
|
||
|
} else {
|
||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||
|
mutation, ok := m.(*GroupMutation)
|
||
|
if !ok {
|
||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||
|
}
|
||
|
if err = gu.check(); err != nil {
|
||
|
return 0, err
|
||
|
}
|
||
|
gu.mutation = mutation
|
||
|
affected, err = gu.sqlSave(ctx)
|
||
|
mutation.done = true
|
||
|
return affected, err
|
||
|
})
|
||
|
for i := len(gu.hooks) - 1; i >= 0; i-- {
|
||
|
if gu.hooks[i] == nil {
|
||
|
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||
|
}
|
||
|
mut = gu.hooks[i](mut)
|
||
|
}
|
||
|
if _, err := mut.Mutate(ctx, gu.mutation); err != nil {
|
||
|
return 0, err
|
||
|
}
|
||
|
}
|
||
|
return affected, err
|
||
|
}
|
||
|
|
||
|
// SaveX is like Save, but panics if an error occurs.
|
||
|
func (gu *GroupUpdate) SaveX(ctx context.Context) int {
|
||
|
affected, err := gu.Save(ctx)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return affected
|
||
|
}
|
||
|
|
||
|
// Exec executes the query.
|
||
|
func (gu *GroupUpdate) Exec(ctx context.Context) error {
|
||
|
_, err := gu.Save(ctx)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
func (gu *GroupUpdate) ExecX(ctx context.Context) {
|
||
|
if err := gu.Exec(ctx); err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// defaults sets the default values of the builder before save.
|
||
|
func (gu *GroupUpdate) defaults() {
|
||
|
if _, ok := gu.mutation.UpdatedAt(); !ok {
|
||
|
v := group.UpdateDefaultUpdatedAt()
|
||
|
gu.mutation.SetUpdatedAt(v)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// check runs all checks and user-defined validators on the builder.
|
||
|
func (gu *GroupUpdate) check() error {
|
||
|
if v, ok := gu.mutation.Name(); ok {
|
||
|
if err := group.NameValidator(v); err != nil {
|
||
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Group.name": %w`, err)}
|
||
|
}
|
||
|
}
|
||
|
if v, ok := gu.mutation.Currency(); ok {
|
||
|
if err := group.CurrencyValidator(v); err != nil {
|
||
|
return &ValidationError{Name: "currency", err: fmt.Errorf(`ent: validator failed for field "Group.currency": %w`, err)}
|
||
|
}
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||
|
_spec := &sqlgraph.UpdateSpec{
|
||
|
Node: &sqlgraph.NodeSpec{
|
||
|
Table: group.Table,
|
||
|
Columns: group.Columns,
|
||
|
ID: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: group.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
if ps := gu.mutation.predicates; len(ps) > 0 {
|
||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||
|
for i := range ps {
|
||
|
ps[i](selector)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if value, ok := gu.mutation.UpdatedAt(); ok {
|
||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeTime,
|
||
|
Value: value,
|
||
|
Column: group.FieldUpdatedAt,
|
||
|
})
|
||
|
}
|
||
|
if value, ok := gu.mutation.Name(); ok {
|
||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeString,
|
||
|
Value: value,
|
||
|
Column: group.FieldName,
|
||
|
})
|
||
|
}
|
||
|
if value, ok := gu.mutation.Currency(); ok {
|
||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeEnum,
|
||
|
Value: value,
|
||
|
Column: group.FieldCurrency,
|
||
|
})
|
||
|
}
|
||
|
if gu.mutation.UsersCleared() {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.O2M,
|
||
|
Inverse: false,
|
||
|
Table: group.UsersTable,
|
||
|
Columns: []string{group.UsersColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: user.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||
|
}
|
||
|
if nodes := gu.mutation.RemovedUsersIDs(); len(nodes) > 0 && !gu.mutation.UsersCleared() {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.O2M,
|
||
|
Inverse: false,
|
||
|
Table: group.UsersTable,
|
||
|
Columns: []string{group.UsersColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: user.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
for _, k := range nodes {
|
||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||
|
}
|
||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||
|
}
|
||
|
if nodes := gu.mutation.UsersIDs(); len(nodes) > 0 {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.O2M,
|
||
|
Inverse: false,
|
||
|
Table: group.UsersTable,
|
||
|
Columns: []string{group.UsersColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: user.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
for _, k := range nodes {
|
||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||
|
}
|
||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||
|
}
|
||
|
if gu.mutation.LocationsCleared() {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.O2M,
|
||
|
Inverse: false,
|
||
|
Table: group.LocationsTable,
|
||
|
Columns: []string{group.LocationsColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: location.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||
|
}
|
||
|
if nodes := gu.mutation.RemovedLocationsIDs(); len(nodes) > 0 && !gu.mutation.LocationsCleared() {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.O2M,
|
||
|
Inverse: false,
|
||
|
Table: group.LocationsTable,
|
||
|
Columns: []string{group.LocationsColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: location.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
for _, k := range nodes {
|
||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||
|
}
|
||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||
|
}
|
||
|
if nodes := gu.mutation.LocationsIDs(); len(nodes) > 0 {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.O2M,
|
||
|
Inverse: false,
|
||
|
Table: group.LocationsTable,
|
||
|
Columns: []string{group.LocationsColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: location.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
for _, k := range nodes {
|
||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||
|
}
|
||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||
|
}
|
||
|
if gu.mutation.ItemsCleared() {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.O2M,
|
||
|
Inverse: false,
|
||
|
Table: group.ItemsTable,
|
||
|
Columns: []string{group.ItemsColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: item.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||
|
}
|
||
|
if nodes := gu.mutation.RemovedItemsIDs(); len(nodes) > 0 && !gu.mutation.ItemsCleared() {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.O2M,
|
||
|
Inverse: false,
|
||
|
Table: group.ItemsTable,
|
||
|
Columns: []string{group.ItemsColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: item.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
for _, k := range nodes {
|
||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||
|
}
|
||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||
|
}
|
||
|
if nodes := gu.mutation.ItemsIDs(); len(nodes) > 0 {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.O2M,
|
||
|
Inverse: false,
|
||
|
Table: group.ItemsTable,
|
||
|
Columns: []string{group.ItemsColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: item.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
for _, k := range nodes {
|
||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||
|
}
|
||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||
|
}
|
||
|
if gu.mutation.LabelsCleared() {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.O2M,
|
||
|
Inverse: false,
|
||
|
Table: group.LabelsTable,
|
||
|
Columns: []string{group.LabelsColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: label.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||
|
}
|
||
|
if nodes := gu.mutation.RemovedLabelsIDs(); len(nodes) > 0 && !gu.mutation.LabelsCleared() {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.O2M,
|
||
|
Inverse: false,
|
||
|
Table: group.LabelsTable,
|
||
|
Columns: []string{group.LabelsColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: label.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
for _, k := range nodes {
|
||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||
|
}
|
||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||
|
}
|
||
|
if nodes := gu.mutation.LabelsIDs(); len(nodes) > 0 {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.O2M,
|
||
|
Inverse: false,
|
||
|
Table: group.LabelsTable,
|
||
|
Columns: []string{group.LabelsColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: label.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
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, gu.driver, _spec); err != nil {
|
||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||
|
err = &NotFoundError{group.Label}
|
||
|
} else if sqlgraph.IsConstraintError(err) {
|
||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||
|
}
|
||
|
return 0, err
|
||
|
}
|
||
|
return n, nil
|
||
|
}
|
||
|
|
||
|
// GroupUpdateOne is the builder for updating a single Group entity.
|
||
|
type GroupUpdateOne struct {
|
||
|
config
|
||
|
fields []string
|
||
|
hooks []Hook
|
||
|
mutation *GroupMutation
|
||
|
}
|
||
|
|
||
|
// SetUpdatedAt sets the "updated_at" field.
|
||
|
func (guo *GroupUpdateOne) SetUpdatedAt(t time.Time) *GroupUpdateOne {
|
||
|
guo.mutation.SetUpdatedAt(t)
|
||
|
return guo
|
||
|
}
|
||
|
|
||
|
// SetName sets the "name" field.
|
||
|
func (guo *GroupUpdateOne) SetName(s string) *GroupUpdateOne {
|
||
|
guo.mutation.SetName(s)
|
||
|
return guo
|
||
|
}
|
||
|
|
||
|
// SetCurrency sets the "currency" field.
|
||
|
func (guo *GroupUpdateOne) SetCurrency(gr group.Currency) *GroupUpdateOne {
|
||
|
guo.mutation.SetCurrency(gr)
|
||
|
return guo
|
||
|
}
|
||
|
|
||
|
// SetNillableCurrency sets the "currency" field if the given value is not nil.
|
||
|
func (guo *GroupUpdateOne) SetNillableCurrency(gr *group.Currency) *GroupUpdateOne {
|
||
|
if gr != nil {
|
||
|
guo.SetCurrency(*gr)
|
||
|
}
|
||
|
return guo
|
||
|
}
|
||
|
|
||
|
// AddUserIDs adds the "users" edge to the User entity by IDs.
|
||
|
func (guo *GroupUpdateOne) AddUserIDs(ids ...uuid.UUID) *GroupUpdateOne {
|
||
|
guo.mutation.AddUserIDs(ids...)
|
||
|
return guo
|
||
|
}
|
||
|
|
||
|
// AddUsers adds the "users" edges to the User entity.
|
||
|
func (guo *GroupUpdateOne) AddUsers(u ...*User) *GroupUpdateOne {
|
||
|
ids := make([]uuid.UUID, len(u))
|
||
|
for i := range u {
|
||
|
ids[i] = u[i].ID
|
||
|
}
|
||
|
return guo.AddUserIDs(ids...)
|
||
|
}
|
||
|
|
||
|
// AddLocationIDs adds the "locations" edge to the Location entity by IDs.
|
||
|
func (guo *GroupUpdateOne) AddLocationIDs(ids ...uuid.UUID) *GroupUpdateOne {
|
||
|
guo.mutation.AddLocationIDs(ids...)
|
||
|
return guo
|
||
|
}
|
||
|
|
||
|
// AddLocations adds the "locations" edges to the Location entity.
|
||
|
func (guo *GroupUpdateOne) AddLocations(l ...*Location) *GroupUpdateOne {
|
||
|
ids := make([]uuid.UUID, len(l))
|
||
|
for i := range l {
|
||
|
ids[i] = l[i].ID
|
||
|
}
|
||
|
return guo.AddLocationIDs(ids...)
|
||
|
}
|
||
|
|
||
|
// AddItemIDs adds the "items" edge to the Item entity by IDs.
|
||
|
func (guo *GroupUpdateOne) AddItemIDs(ids ...uuid.UUID) *GroupUpdateOne {
|
||
|
guo.mutation.AddItemIDs(ids...)
|
||
|
return guo
|
||
|
}
|
||
|
|
||
|
// AddItems adds the "items" edges to the Item entity.
|
||
|
func (guo *GroupUpdateOne) AddItems(i ...*Item) *GroupUpdateOne {
|
||
|
ids := make([]uuid.UUID, len(i))
|
||
|
for j := range i {
|
||
|
ids[j] = i[j].ID
|
||
|
}
|
||
|
return guo.AddItemIDs(ids...)
|
||
|
}
|
||
|
|
||
|
// AddLabelIDs adds the "labels" edge to the Label entity by IDs.
|
||
|
func (guo *GroupUpdateOne) AddLabelIDs(ids ...uuid.UUID) *GroupUpdateOne {
|
||
|
guo.mutation.AddLabelIDs(ids...)
|
||
|
return guo
|
||
|
}
|
||
|
|
||
|
// AddLabels adds the "labels" edges to the Label entity.
|
||
|
func (guo *GroupUpdateOne) AddLabels(l ...*Label) *GroupUpdateOne {
|
||
|
ids := make([]uuid.UUID, len(l))
|
||
|
for i := range l {
|
||
|
ids[i] = l[i].ID
|
||
|
}
|
||
|
return guo.AddLabelIDs(ids...)
|
||
|
}
|
||
|
|
||
|
// Mutation returns the GroupMutation object of the builder.
|
||
|
func (guo *GroupUpdateOne) Mutation() *GroupMutation {
|
||
|
return guo.mutation
|
||
|
}
|
||
|
|
||
|
// ClearUsers clears all "users" edges to the User entity.
|
||
|
func (guo *GroupUpdateOne) ClearUsers() *GroupUpdateOne {
|
||
|
guo.mutation.ClearUsers()
|
||
|
return guo
|
||
|
}
|
||
|
|
||
|
// RemoveUserIDs removes the "users" edge to User entities by IDs.
|
||
|
func (guo *GroupUpdateOne) RemoveUserIDs(ids ...uuid.UUID) *GroupUpdateOne {
|
||
|
guo.mutation.RemoveUserIDs(ids...)
|
||
|
return guo
|
||
|
}
|
||
|
|
||
|
// RemoveUsers removes "users" edges to User entities.
|
||
|
func (guo *GroupUpdateOne) RemoveUsers(u ...*User) *GroupUpdateOne {
|
||
|
ids := make([]uuid.UUID, len(u))
|
||
|
for i := range u {
|
||
|
ids[i] = u[i].ID
|
||
|
}
|
||
|
return guo.RemoveUserIDs(ids...)
|
||
|
}
|
||
|
|
||
|
// ClearLocations clears all "locations" edges to the Location entity.
|
||
|
func (guo *GroupUpdateOne) ClearLocations() *GroupUpdateOne {
|
||
|
guo.mutation.ClearLocations()
|
||
|
return guo
|
||
|
}
|
||
|
|
||
|
// RemoveLocationIDs removes the "locations" edge to Location entities by IDs.
|
||
|
func (guo *GroupUpdateOne) RemoveLocationIDs(ids ...uuid.UUID) *GroupUpdateOne {
|
||
|
guo.mutation.RemoveLocationIDs(ids...)
|
||
|
return guo
|
||
|
}
|
||
|
|
||
|
// RemoveLocations removes "locations" edges to Location entities.
|
||
|
func (guo *GroupUpdateOne) RemoveLocations(l ...*Location) *GroupUpdateOne {
|
||
|
ids := make([]uuid.UUID, len(l))
|
||
|
for i := range l {
|
||
|
ids[i] = l[i].ID
|
||
|
}
|
||
|
return guo.RemoveLocationIDs(ids...)
|
||
|
}
|
||
|
|
||
|
// ClearItems clears all "items" edges to the Item entity.
|
||
|
func (guo *GroupUpdateOne) ClearItems() *GroupUpdateOne {
|
||
|
guo.mutation.ClearItems()
|
||
|
return guo
|
||
|
}
|
||
|
|
||
|
// RemoveItemIDs removes the "items" edge to Item entities by IDs.
|
||
|
func (guo *GroupUpdateOne) RemoveItemIDs(ids ...uuid.UUID) *GroupUpdateOne {
|
||
|
guo.mutation.RemoveItemIDs(ids...)
|
||
|
return guo
|
||
|
}
|
||
|
|
||
|
// RemoveItems removes "items" edges to Item entities.
|
||
|
func (guo *GroupUpdateOne) RemoveItems(i ...*Item) *GroupUpdateOne {
|
||
|
ids := make([]uuid.UUID, len(i))
|
||
|
for j := range i {
|
||
|
ids[j] = i[j].ID
|
||
|
}
|
||
|
return guo.RemoveItemIDs(ids...)
|
||
|
}
|
||
|
|
||
|
// ClearLabels clears all "labels" edges to the Label entity.
|
||
|
func (guo *GroupUpdateOne) ClearLabels() *GroupUpdateOne {
|
||
|
guo.mutation.ClearLabels()
|
||
|
return guo
|
||
|
}
|
||
|
|
||
|
// RemoveLabelIDs removes the "labels" edge to Label entities by IDs.
|
||
|
func (guo *GroupUpdateOne) RemoveLabelIDs(ids ...uuid.UUID) *GroupUpdateOne {
|
||
|
guo.mutation.RemoveLabelIDs(ids...)
|
||
|
return guo
|
||
|
}
|
||
|
|
||
|
// RemoveLabels removes "labels" edges to Label entities.
|
||
|
func (guo *GroupUpdateOne) RemoveLabels(l ...*Label) *GroupUpdateOne {
|
||
|
ids := make([]uuid.UUID, len(l))
|
||
|
for i := range l {
|
||
|
ids[i] = l[i].ID
|
||
|
}
|
||
|
return guo.RemoveLabelIDs(ids...)
|
||
|
}
|
||
|
|
||
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
||
|
// The default is selecting all fields defined in the entity schema.
|
||
|
func (guo *GroupUpdateOne) Select(field string, fields ...string) *GroupUpdateOne {
|
||
|
guo.fields = append([]string{field}, fields...)
|
||
|
return guo
|
||
|
}
|
||
|
|
||
|
// Save executes the query and returns the updated Group entity.
|
||
|
func (guo *GroupUpdateOne) Save(ctx context.Context) (*Group, error) {
|
||
|
var (
|
||
|
err error
|
||
|
node *Group
|
||
|
)
|
||
|
guo.defaults()
|
||
|
if len(guo.hooks) == 0 {
|
||
|
if err = guo.check(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
node, err = guo.sqlSave(ctx)
|
||
|
} else {
|
||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||
|
mutation, ok := m.(*GroupMutation)
|
||
|
if !ok {
|
||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||
|
}
|
||
|
if err = guo.check(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
guo.mutation = mutation
|
||
|
node, err = guo.sqlSave(ctx)
|
||
|
mutation.done = true
|
||
|
return node, err
|
||
|
})
|
||
|
for i := len(guo.hooks) - 1; i >= 0; i-- {
|
||
|
if guo.hooks[i] == nil {
|
||
|
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||
|
}
|
||
|
mut = guo.hooks[i](mut)
|
||
|
}
|
||
|
v, err := mut.Mutate(ctx, guo.mutation)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
nv, ok := v.(*Group)
|
||
|
if !ok {
|
||
|
return nil, fmt.Errorf("unexpected node type %T returned from GroupMutation", v)
|
||
|
}
|
||
|
node = nv
|
||
|
}
|
||
|
return node, err
|
||
|
}
|
||
|
|
||
|
// SaveX is like Save, but panics if an error occurs.
|
||
|
func (guo *GroupUpdateOne) SaveX(ctx context.Context) *Group {
|
||
|
node, err := guo.Save(ctx)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return node
|
||
|
}
|
||
|
|
||
|
// Exec executes the query on the entity.
|
||
|
func (guo *GroupUpdateOne) Exec(ctx context.Context) error {
|
||
|
_, err := guo.Save(ctx)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
func (guo *GroupUpdateOne) ExecX(ctx context.Context) {
|
||
|
if err := guo.Exec(ctx); err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// defaults sets the default values of the builder before save.
|
||
|
func (guo *GroupUpdateOne) defaults() {
|
||
|
if _, ok := guo.mutation.UpdatedAt(); !ok {
|
||
|
v := group.UpdateDefaultUpdatedAt()
|
||
|
guo.mutation.SetUpdatedAt(v)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// check runs all checks and user-defined validators on the builder.
|
||
|
func (guo *GroupUpdateOne) check() error {
|
||
|
if v, ok := guo.mutation.Name(); ok {
|
||
|
if err := group.NameValidator(v); err != nil {
|
||
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Group.name": %w`, err)}
|
||
|
}
|
||
|
}
|
||
|
if v, ok := guo.mutation.Currency(); ok {
|
||
|
if err := group.CurrencyValidator(v); err != nil {
|
||
|
return &ValidationError{Name: "currency", err: fmt.Errorf(`ent: validator failed for field "Group.currency": %w`, err)}
|
||
|
}
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error) {
|
||
|
_spec := &sqlgraph.UpdateSpec{
|
||
|
Node: &sqlgraph.NodeSpec{
|
||
|
Table: group.Table,
|
||
|
Columns: group.Columns,
|
||
|
ID: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: group.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
id, ok := guo.mutation.ID()
|
||
|
if !ok {
|
||
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Group.id" for update`)}
|
||
|
}
|
||
|
_spec.Node.ID.Value = id
|
||
|
if fields := guo.fields; len(fields) > 0 {
|
||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||
|
_spec.Node.Columns = append(_spec.Node.Columns, group.FieldID)
|
||
|
for _, f := range fields {
|
||
|
if !group.ValidColumn(f) {
|
||
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||
|
}
|
||
|
if f != group.FieldID {
|
||
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if ps := guo.mutation.predicates; len(ps) > 0 {
|
||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||
|
for i := range ps {
|
||
|
ps[i](selector)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if value, ok := guo.mutation.UpdatedAt(); ok {
|
||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeTime,
|
||
|
Value: value,
|
||
|
Column: group.FieldUpdatedAt,
|
||
|
})
|
||
|
}
|
||
|
if value, ok := guo.mutation.Name(); ok {
|
||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeString,
|
||
|
Value: value,
|
||
|
Column: group.FieldName,
|
||
|
})
|
||
|
}
|
||
|
if value, ok := guo.mutation.Currency(); ok {
|
||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeEnum,
|
||
|
Value: value,
|
||
|
Column: group.FieldCurrency,
|
||
|
})
|
||
|
}
|
||
|
if guo.mutation.UsersCleared() {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.O2M,
|
||
|
Inverse: false,
|
||
|
Table: group.UsersTable,
|
||
|
Columns: []string{group.UsersColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: user.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||
|
}
|
||
|
if nodes := guo.mutation.RemovedUsersIDs(); len(nodes) > 0 && !guo.mutation.UsersCleared() {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.O2M,
|
||
|
Inverse: false,
|
||
|
Table: group.UsersTable,
|
||
|
Columns: []string{group.UsersColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: user.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
for _, k := range nodes {
|
||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||
|
}
|
||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||
|
}
|
||
|
if nodes := guo.mutation.UsersIDs(); len(nodes) > 0 {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.O2M,
|
||
|
Inverse: false,
|
||
|
Table: group.UsersTable,
|
||
|
Columns: []string{group.UsersColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: user.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
for _, k := range nodes {
|
||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||
|
}
|
||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||
|
}
|
||
|
if guo.mutation.LocationsCleared() {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.O2M,
|
||
|
Inverse: false,
|
||
|
Table: group.LocationsTable,
|
||
|
Columns: []string{group.LocationsColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: location.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||
|
}
|
||
|
if nodes := guo.mutation.RemovedLocationsIDs(); len(nodes) > 0 && !guo.mutation.LocationsCleared() {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.O2M,
|
||
|
Inverse: false,
|
||
|
Table: group.LocationsTable,
|
||
|
Columns: []string{group.LocationsColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: location.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
for _, k := range nodes {
|
||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||
|
}
|
||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||
|
}
|
||
|
if nodes := guo.mutation.LocationsIDs(); len(nodes) > 0 {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.O2M,
|
||
|
Inverse: false,
|
||
|
Table: group.LocationsTable,
|
||
|
Columns: []string{group.LocationsColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: location.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
for _, k := range nodes {
|
||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||
|
}
|
||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||
|
}
|
||
|
if guo.mutation.ItemsCleared() {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.O2M,
|
||
|
Inverse: false,
|
||
|
Table: group.ItemsTable,
|
||
|
Columns: []string{group.ItemsColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: item.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||
|
}
|
||
|
if nodes := guo.mutation.RemovedItemsIDs(); len(nodes) > 0 && !guo.mutation.ItemsCleared() {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.O2M,
|
||
|
Inverse: false,
|
||
|
Table: group.ItemsTable,
|
||
|
Columns: []string{group.ItemsColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: item.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
for _, k := range nodes {
|
||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||
|
}
|
||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||
|
}
|
||
|
if nodes := guo.mutation.ItemsIDs(); len(nodes) > 0 {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.O2M,
|
||
|
Inverse: false,
|
||
|
Table: group.ItemsTable,
|
||
|
Columns: []string{group.ItemsColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: item.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
for _, k := range nodes {
|
||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||
|
}
|
||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||
|
}
|
||
|
if guo.mutation.LabelsCleared() {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.O2M,
|
||
|
Inverse: false,
|
||
|
Table: group.LabelsTable,
|
||
|
Columns: []string{group.LabelsColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: label.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||
|
}
|
||
|
if nodes := guo.mutation.RemovedLabelsIDs(); len(nodes) > 0 && !guo.mutation.LabelsCleared() {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.O2M,
|
||
|
Inverse: false,
|
||
|
Table: group.LabelsTable,
|
||
|
Columns: []string{group.LabelsColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: label.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
for _, k := range nodes {
|
||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||
|
}
|
||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||
|
}
|
||
|
if nodes := guo.mutation.LabelsIDs(); len(nodes) > 0 {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.O2M,
|
||
|
Inverse: false,
|
||
|
Table: group.LabelsTable,
|
||
|
Columns: []string{group.LabelsColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: &sqlgraph.FieldSpec{
|
||
|
Type: field.TypeUUID,
|
||
|
Column: label.FieldID,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
for _, k := range nodes {
|
||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||
|
}
|
||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||
|
}
|
||
|
_node = &Group{config: guo.config}
|
||
|
_spec.Assign = _node.assignValues
|
||
|
_spec.ScanValues = _node.scanValues
|
||
|
if err = sqlgraph.UpdateNode(ctx, guo.driver, _spec); err != nil {
|
||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||
|
err = &NotFoundError{group.Label}
|
||
|
} else if sqlgraph.IsConstraintError(err) {
|
||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||
|
}
|
||
|
return nil, err
|
||
|
}
|
||
|
return _node, nil
|
||
|
}
|