role_update.go•22.9 kB
// 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/dialect/sql/sqljson"
"entgo.io/ent/schema/field"
"github.com/Southclaws/storyden/internal/ent/account"
"github.com/Southclaws/storyden/internal/ent/accountroles"
"github.com/Southclaws/storyden/internal/ent/predicate"
"github.com/Southclaws/storyden/internal/ent/role"
"github.com/rs/xid"
)
// RoleUpdate is the builder for updating Role entities.
type RoleUpdate struct {
config
hooks []Hook
mutation *RoleMutation
modifiers []func(*sql.UpdateBuilder)
}
// Where appends a list predicates to the RoleUpdate builder.
func (_u *RoleUpdate) Where(ps ...predicate.Role) *RoleUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *RoleUpdate) SetUpdatedAt(v time.Time) *RoleUpdate {
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetName sets the "name" field.
func (_u *RoleUpdate) SetName(v string) *RoleUpdate {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *RoleUpdate) SetNillableName(v *string) *RoleUpdate {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetColour sets the "colour" field.
func (_u *RoleUpdate) SetColour(v string) *RoleUpdate {
_u.mutation.SetColour(v)
return _u
}
// SetNillableColour sets the "colour" field if the given value is not nil.
func (_u *RoleUpdate) SetNillableColour(v *string) *RoleUpdate {
if v != nil {
_u.SetColour(*v)
}
return _u
}
// SetPermissions sets the "permissions" field.
func (_u *RoleUpdate) SetPermissions(v []string) *RoleUpdate {
_u.mutation.SetPermissions(v)
return _u
}
// AppendPermissions appends value to the "permissions" field.
func (_u *RoleUpdate) AppendPermissions(v []string) *RoleUpdate {
_u.mutation.AppendPermissions(v)
return _u
}
// SetSortKey sets the "sort_key" field.
func (_u *RoleUpdate) SetSortKey(v float64) *RoleUpdate {
_u.mutation.ResetSortKey()
_u.mutation.SetSortKey(v)
return _u
}
// SetNillableSortKey sets the "sort_key" field if the given value is not nil.
func (_u *RoleUpdate) SetNillableSortKey(v *float64) *RoleUpdate {
if v != nil {
_u.SetSortKey(*v)
}
return _u
}
// AddSortKey adds value to the "sort_key" field.
func (_u *RoleUpdate) AddSortKey(v float64) *RoleUpdate {
_u.mutation.AddSortKey(v)
return _u
}
// AddAccountIDs adds the "accounts" edge to the Account entity by IDs.
func (_u *RoleUpdate) AddAccountIDs(ids ...xid.ID) *RoleUpdate {
_u.mutation.AddAccountIDs(ids...)
return _u
}
// AddAccounts adds the "accounts" edges to the Account entity.
func (_u *RoleUpdate) AddAccounts(v ...*Account) *RoleUpdate {
ids := make([]xid.ID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddAccountIDs(ids...)
}
// AddAccountRoleIDs adds the "account_roles" edge to the AccountRoles entity by IDs.
func (_u *RoleUpdate) AddAccountRoleIDs(ids ...xid.ID) *RoleUpdate {
_u.mutation.AddAccountRoleIDs(ids...)
return _u
}
// AddAccountRoles adds the "account_roles" edges to the AccountRoles entity.
func (_u *RoleUpdate) AddAccountRoles(v ...*AccountRoles) *RoleUpdate {
ids := make([]xid.ID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddAccountRoleIDs(ids...)
}
// Mutation returns the RoleMutation object of the builder.
func (_u *RoleUpdate) Mutation() *RoleMutation {
return _u.mutation
}
// ClearAccounts clears all "accounts" edges to the Account entity.
func (_u *RoleUpdate) ClearAccounts() *RoleUpdate {
_u.mutation.ClearAccounts()
return _u
}
// RemoveAccountIDs removes the "accounts" edge to Account entities by IDs.
func (_u *RoleUpdate) RemoveAccountIDs(ids ...xid.ID) *RoleUpdate {
_u.mutation.RemoveAccountIDs(ids...)
return _u
}
// RemoveAccounts removes "accounts" edges to Account entities.
func (_u *RoleUpdate) RemoveAccounts(v ...*Account) *RoleUpdate {
ids := make([]xid.ID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveAccountIDs(ids...)
}
// ClearAccountRoles clears all "account_roles" edges to the AccountRoles entity.
func (_u *RoleUpdate) ClearAccountRoles() *RoleUpdate {
_u.mutation.ClearAccountRoles()
return _u
}
// RemoveAccountRoleIDs removes the "account_roles" edge to AccountRoles entities by IDs.
func (_u *RoleUpdate) RemoveAccountRoleIDs(ids ...xid.ID) *RoleUpdate {
_u.mutation.RemoveAccountRoleIDs(ids...)
return _u
}
// RemoveAccountRoles removes "account_roles" edges to AccountRoles entities.
func (_u *RoleUpdate) RemoveAccountRoles(v ...*AccountRoles) *RoleUpdate {
ids := make([]xid.ID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveAccountRoleIDs(ids...)
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *RoleUpdate) Save(ctx context.Context) (int, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *RoleUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *RoleUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *RoleUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_u *RoleUpdate) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok {
v := role.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *RoleUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *RoleUpdate {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *RoleUpdate) sqlSave(ctx context.Context) (_node int, err error) {
_spec := sqlgraph.NewUpdateSpec(role.Table, role.Columns, sqlgraph.NewFieldSpec(role.FieldID, field.TypeString))
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(role.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.Name(); ok {
_spec.SetField(role.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.Colour(); ok {
_spec.SetField(role.FieldColour, field.TypeString, value)
}
if value, ok := _u.mutation.Permissions(); ok {
_spec.SetField(role.FieldPermissions, field.TypeJSON, value)
}
if value, ok := _u.mutation.AppendedPermissions(); ok {
_spec.AddModifier(func(u *sql.UpdateBuilder) {
sqljson.Append(u, role.FieldPermissions, value)
})
}
if value, ok := _u.mutation.SortKey(); ok {
_spec.SetField(role.FieldSortKey, field.TypeFloat64, value)
}
if value, ok := _u.mutation.AddedSortKey(); ok {
_spec.AddField(role.FieldSortKey, field.TypeFloat64, value)
}
if _u.mutation.AccountsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: role.AccountsTable,
Columns: role.AccountsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeString),
},
}
createE := &AccountRolesCreate{config: _u.config, mutation: newAccountRolesMutation(_u.config, OpCreate)}
createE.defaults()
_, specE := createE.createSpec()
edge.Target.Fields = specE.Fields
if specE.ID.Value != nil {
edge.Target.Fields = append(edge.Target.Fields, specE.ID)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedAccountsIDs(); len(nodes) > 0 && !_u.mutation.AccountsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: role.AccountsTable,
Columns: role.AccountsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
createE := &AccountRolesCreate{config: _u.config, mutation: newAccountRolesMutation(_u.config, OpCreate)}
createE.defaults()
_, specE := createE.createSpec()
edge.Target.Fields = specE.Fields
if specE.ID.Value != nil {
edge.Target.Fields = append(edge.Target.Fields, specE.ID)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.AccountsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: role.AccountsTable,
Columns: role.AccountsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
createE := &AccountRolesCreate{config: _u.config, mutation: newAccountRolesMutation(_u.config, OpCreate)}
createE.defaults()
_, specE := createE.createSpec()
edge.Target.Fields = specE.Fields
if specE.ID.Value != nil {
edge.Target.Fields = append(edge.Target.Fields, specE.ID)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.AccountRolesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: true,
Table: role.AccountRolesTable,
Columns: []string{role.AccountRolesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(accountroles.FieldID, field.TypeString),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedAccountRolesIDs(); len(nodes) > 0 && !_u.mutation.AccountRolesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: true,
Table: role.AccountRolesTable,
Columns: []string{role.AccountRolesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(accountroles.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.AccountRolesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: true,
Table: role.AccountRolesTable,
Columns: []string{role.AccountRolesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(accountroles.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.AddModifiers(_u.modifiers...)
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{role.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// RoleUpdateOne is the builder for updating a single Role entity.
type RoleUpdateOne struct {
config
fields []string
hooks []Hook
mutation *RoleMutation
modifiers []func(*sql.UpdateBuilder)
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *RoleUpdateOne) SetUpdatedAt(v time.Time) *RoleUpdateOne {
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetName sets the "name" field.
func (_u *RoleUpdateOne) SetName(v string) *RoleUpdateOne {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *RoleUpdateOne) SetNillableName(v *string) *RoleUpdateOne {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetColour sets the "colour" field.
func (_u *RoleUpdateOne) SetColour(v string) *RoleUpdateOne {
_u.mutation.SetColour(v)
return _u
}
// SetNillableColour sets the "colour" field if the given value is not nil.
func (_u *RoleUpdateOne) SetNillableColour(v *string) *RoleUpdateOne {
if v != nil {
_u.SetColour(*v)
}
return _u
}
// SetPermissions sets the "permissions" field.
func (_u *RoleUpdateOne) SetPermissions(v []string) *RoleUpdateOne {
_u.mutation.SetPermissions(v)
return _u
}
// AppendPermissions appends value to the "permissions" field.
func (_u *RoleUpdateOne) AppendPermissions(v []string) *RoleUpdateOne {
_u.mutation.AppendPermissions(v)
return _u
}
// SetSortKey sets the "sort_key" field.
func (_u *RoleUpdateOne) SetSortKey(v float64) *RoleUpdateOne {
_u.mutation.ResetSortKey()
_u.mutation.SetSortKey(v)
return _u
}
// SetNillableSortKey sets the "sort_key" field if the given value is not nil.
func (_u *RoleUpdateOne) SetNillableSortKey(v *float64) *RoleUpdateOne {
if v != nil {
_u.SetSortKey(*v)
}
return _u
}
// AddSortKey adds value to the "sort_key" field.
func (_u *RoleUpdateOne) AddSortKey(v float64) *RoleUpdateOne {
_u.mutation.AddSortKey(v)
return _u
}
// AddAccountIDs adds the "accounts" edge to the Account entity by IDs.
func (_u *RoleUpdateOne) AddAccountIDs(ids ...xid.ID) *RoleUpdateOne {
_u.mutation.AddAccountIDs(ids...)
return _u
}
// AddAccounts adds the "accounts" edges to the Account entity.
func (_u *RoleUpdateOne) AddAccounts(v ...*Account) *RoleUpdateOne {
ids := make([]xid.ID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddAccountIDs(ids...)
}
// AddAccountRoleIDs adds the "account_roles" edge to the AccountRoles entity by IDs.
func (_u *RoleUpdateOne) AddAccountRoleIDs(ids ...xid.ID) *RoleUpdateOne {
_u.mutation.AddAccountRoleIDs(ids...)
return _u
}
// AddAccountRoles adds the "account_roles" edges to the AccountRoles entity.
func (_u *RoleUpdateOne) AddAccountRoles(v ...*AccountRoles) *RoleUpdateOne {
ids := make([]xid.ID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddAccountRoleIDs(ids...)
}
// Mutation returns the RoleMutation object of the builder.
func (_u *RoleUpdateOne) Mutation() *RoleMutation {
return _u.mutation
}
// ClearAccounts clears all "accounts" edges to the Account entity.
func (_u *RoleUpdateOne) ClearAccounts() *RoleUpdateOne {
_u.mutation.ClearAccounts()
return _u
}
// RemoveAccountIDs removes the "accounts" edge to Account entities by IDs.
func (_u *RoleUpdateOne) RemoveAccountIDs(ids ...xid.ID) *RoleUpdateOne {
_u.mutation.RemoveAccountIDs(ids...)
return _u
}
// RemoveAccounts removes "accounts" edges to Account entities.
func (_u *RoleUpdateOne) RemoveAccounts(v ...*Account) *RoleUpdateOne {
ids := make([]xid.ID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveAccountIDs(ids...)
}
// ClearAccountRoles clears all "account_roles" edges to the AccountRoles entity.
func (_u *RoleUpdateOne) ClearAccountRoles() *RoleUpdateOne {
_u.mutation.ClearAccountRoles()
return _u
}
// RemoveAccountRoleIDs removes the "account_roles" edge to AccountRoles entities by IDs.
func (_u *RoleUpdateOne) RemoveAccountRoleIDs(ids ...xid.ID) *RoleUpdateOne {
_u.mutation.RemoveAccountRoleIDs(ids...)
return _u
}
// RemoveAccountRoles removes "account_roles" edges to AccountRoles entities.
func (_u *RoleUpdateOne) RemoveAccountRoles(v ...*AccountRoles) *RoleUpdateOne {
ids := make([]xid.ID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveAccountRoleIDs(ids...)
}
// Where appends a list predicates to the RoleUpdate builder.
func (_u *RoleUpdateOne) Where(ps ...predicate.Role) *RoleUpdateOne {
_u.mutation.Where(ps...)
return _u
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (_u *RoleUpdateOne) Select(field string, fields ...string) *RoleUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated Role entity.
func (_u *RoleUpdateOne) Save(ctx context.Context) (*Role, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *RoleUpdateOne) SaveX(ctx context.Context) *Role {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *RoleUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *RoleUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_u *RoleUpdateOne) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok {
v := role.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *RoleUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *RoleUpdateOne {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *RoleUpdateOne) sqlSave(ctx context.Context) (_node *Role, err error) {
_spec := sqlgraph.NewUpdateSpec(role.Table, role.Columns, sqlgraph.NewFieldSpec(role.FieldID, field.TypeString))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Role.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := _u.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, role.FieldID)
for _, f := range fields {
if !role.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != role.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(role.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.Name(); ok {
_spec.SetField(role.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.Colour(); ok {
_spec.SetField(role.FieldColour, field.TypeString, value)
}
if value, ok := _u.mutation.Permissions(); ok {
_spec.SetField(role.FieldPermissions, field.TypeJSON, value)
}
if value, ok := _u.mutation.AppendedPermissions(); ok {
_spec.AddModifier(func(u *sql.UpdateBuilder) {
sqljson.Append(u, role.FieldPermissions, value)
})
}
if value, ok := _u.mutation.SortKey(); ok {
_spec.SetField(role.FieldSortKey, field.TypeFloat64, value)
}
if value, ok := _u.mutation.AddedSortKey(); ok {
_spec.AddField(role.FieldSortKey, field.TypeFloat64, value)
}
if _u.mutation.AccountsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: role.AccountsTable,
Columns: role.AccountsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeString),
},
}
createE := &AccountRolesCreate{config: _u.config, mutation: newAccountRolesMutation(_u.config, OpCreate)}
createE.defaults()
_, specE := createE.createSpec()
edge.Target.Fields = specE.Fields
if specE.ID.Value != nil {
edge.Target.Fields = append(edge.Target.Fields, specE.ID)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedAccountsIDs(); len(nodes) > 0 && !_u.mutation.AccountsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: role.AccountsTable,
Columns: role.AccountsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
createE := &AccountRolesCreate{config: _u.config, mutation: newAccountRolesMutation(_u.config, OpCreate)}
createE.defaults()
_, specE := createE.createSpec()
edge.Target.Fields = specE.Fields
if specE.ID.Value != nil {
edge.Target.Fields = append(edge.Target.Fields, specE.ID)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.AccountsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: role.AccountsTable,
Columns: role.AccountsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
createE := &AccountRolesCreate{config: _u.config, mutation: newAccountRolesMutation(_u.config, OpCreate)}
createE.defaults()
_, specE := createE.createSpec()
edge.Target.Fields = specE.Fields
if specE.ID.Value != nil {
edge.Target.Fields = append(edge.Target.Fields, specE.ID)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.AccountRolesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: true,
Table: role.AccountRolesTable,
Columns: []string{role.AccountRolesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(accountroles.FieldID, field.TypeString),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedAccountRolesIDs(); len(nodes) > 0 && !_u.mutation.AccountRolesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: true,
Table: role.AccountRolesTable,
Columns: []string{role.AccountRolesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(accountroles.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.AccountRolesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: true,
Table: role.AccountRolesTable,
Columns: []string{role.AccountRolesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(accountroles.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.AddModifiers(_u.modifiers...)
_node = &Role{config: _u.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{role.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}