snapshot of https://github.com/ent/ent.git (master, 2026-09-15; blobs > 131072B omitted)
This commit is contained in:
664
entc/integration/customid/ent/doc_update.go
Normal file
664
entc/integration/customid/ent/doc_update.go
Normal file
@@ -0,0 +1,664 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/customid/ent/doc"
|
||||
"entgo.io/ent/entc/integration/customid/ent/predicate"
|
||||
"entgo.io/ent/entc/integration/customid/ent/schema"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// DocUpdate is the builder for updating Doc entities.
|
||||
type DocUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *DocMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the DocUpdate builder.
|
||||
func (_u *DocUpdate) Where(ps ...predicate.Doc) *DocUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetText sets the "text" field.
|
||||
func (_u *DocUpdate) SetText(v string) *DocUpdate {
|
||||
_u.mutation.SetText(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableText sets the "text" field if the given value is not nil.
|
||||
func (_u *DocUpdate) SetNillableText(v *string) *DocUpdate {
|
||||
if v != nil {
|
||||
_u.SetText(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearText clears the value of the "text" field.
|
||||
func (_u *DocUpdate) ClearText() *DocUpdate {
|
||||
_u.mutation.ClearText()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetParentID sets the "parent" edge to the Doc entity by ID.
|
||||
func (_u *DocUpdate) SetParentID(id schema.DocID) *DocUpdate {
|
||||
_u.mutation.SetParentID(id)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableParentID sets the "parent" edge to the Doc entity by ID if the given value is not nil.
|
||||
func (_u *DocUpdate) SetNillableParentID(id *schema.DocID) *DocUpdate {
|
||||
if id != nil {
|
||||
_u = _u.SetParentID(*id)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetParent sets the "parent" edge to the Doc entity.
|
||||
func (_u *DocUpdate) SetParent(v *Doc) *DocUpdate {
|
||||
return _u.SetParentID(v.ID)
|
||||
}
|
||||
|
||||
// AddChildIDs adds the "children" edge to the Doc entity by IDs.
|
||||
func (_u *DocUpdate) AddChildIDs(ids ...schema.DocID) *DocUpdate {
|
||||
_u.mutation.AddChildIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddChildren adds the "children" edges to the Doc entity.
|
||||
func (_u *DocUpdate) AddChildren(v ...*Doc) *DocUpdate {
|
||||
ids := make([]schema.DocID, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddChildIDs(ids...)
|
||||
}
|
||||
|
||||
// AddRelatedIDs adds the "related" edge to the Doc entity by IDs.
|
||||
func (_u *DocUpdate) AddRelatedIDs(ids ...schema.DocID) *DocUpdate {
|
||||
_u.mutation.AddRelatedIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddRelated adds the "related" edges to the Doc entity.
|
||||
func (_u *DocUpdate) AddRelated(v ...*Doc) *DocUpdate {
|
||||
ids := make([]schema.DocID, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddRelatedIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the DocMutation object of the builder.
|
||||
func (_u *DocUpdate) Mutation() *DocMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearParent clears the "parent" edge to the Doc entity.
|
||||
func (_u *DocUpdate) ClearParent() *DocUpdate {
|
||||
_u.mutation.ClearParent()
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearChildren clears all "children" edges to the Doc entity.
|
||||
func (_u *DocUpdate) ClearChildren() *DocUpdate {
|
||||
_u.mutation.ClearChildren()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveChildIDs removes the "children" edge to Doc entities by IDs.
|
||||
func (_u *DocUpdate) RemoveChildIDs(ids ...schema.DocID) *DocUpdate {
|
||||
_u.mutation.RemoveChildIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveChildren removes "children" edges to Doc entities.
|
||||
func (_u *DocUpdate) RemoveChildren(v ...*Doc) *DocUpdate {
|
||||
ids := make([]schema.DocID, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveChildIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearRelated clears all "related" edges to the Doc entity.
|
||||
func (_u *DocUpdate) ClearRelated() *DocUpdate {
|
||||
_u.mutation.ClearRelated()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveRelatedIDs removes the "related" edge to Doc entities by IDs.
|
||||
func (_u *DocUpdate) RemoveRelatedIDs(ids ...schema.DocID) *DocUpdate {
|
||||
_u.mutation.RemoveRelatedIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveRelated removes "related" edges to Doc entities.
|
||||
func (_u *DocUpdate) RemoveRelated(v ...*Doc) *DocUpdate {
|
||||
ids := make([]schema.DocID, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveRelatedIDs(ids...)
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *DocUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *DocUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *DocUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *DocUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *DocUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(doc.Table, doc.Columns, sqlgraph.NewFieldSpec(doc.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.Text(); ok {
|
||||
_spec.SetField(doc.FieldText, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.TextCleared() {
|
||||
_spec.ClearField(doc.FieldText, field.TypeString)
|
||||
}
|
||||
if _u.mutation.ParentCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: doc.ParentTable,
|
||||
Columns: []string{doc.ParentColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(doc.FieldID, field.TypeString),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.ParentIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: doc.ParentTable,
|
||||
Columns: []string{doc.ParentColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(doc.FieldID, field.TypeString),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _u.mutation.ChildrenCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: doc.ChildrenTable,
|
||||
Columns: []string{doc.ChildrenColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(doc.FieldID, field.TypeString),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedChildrenIDs(); len(nodes) > 0 && !_u.mutation.ChildrenCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: doc.ChildrenTable,
|
||||
Columns: []string{doc.ChildrenColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(doc.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.ChildrenIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: doc.ChildrenTable,
|
||||
Columns: []string{doc.ChildrenColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(doc.FieldID, field.TypeString),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _u.mutation.RelatedCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: doc.RelatedTable,
|
||||
Columns: doc.RelatedPrimaryKey,
|
||||
Bidi: true,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(doc.FieldID, field.TypeString),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedRelatedIDs(); len(nodes) > 0 && !_u.mutation.RelatedCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: doc.RelatedTable,
|
||||
Columns: doc.RelatedPrimaryKey,
|
||||
Bidi: true,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(doc.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.RelatedIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: doc.RelatedTable,
|
||||
Columns: doc.RelatedPrimaryKey,
|
||||
Bidi: true,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(doc.FieldID, field.TypeString),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{doc.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// DocUpdateOne is the builder for updating a single Doc entity.
|
||||
type DocUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *DocMutation
|
||||
}
|
||||
|
||||
// SetText sets the "text" field.
|
||||
func (_u *DocUpdateOne) SetText(v string) *DocUpdateOne {
|
||||
_u.mutation.SetText(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableText sets the "text" field if the given value is not nil.
|
||||
func (_u *DocUpdateOne) SetNillableText(v *string) *DocUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetText(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearText clears the value of the "text" field.
|
||||
func (_u *DocUpdateOne) ClearText() *DocUpdateOne {
|
||||
_u.mutation.ClearText()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetParentID sets the "parent" edge to the Doc entity by ID.
|
||||
func (_u *DocUpdateOne) SetParentID(id schema.DocID) *DocUpdateOne {
|
||||
_u.mutation.SetParentID(id)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableParentID sets the "parent" edge to the Doc entity by ID if the given value is not nil.
|
||||
func (_u *DocUpdateOne) SetNillableParentID(id *schema.DocID) *DocUpdateOne {
|
||||
if id != nil {
|
||||
_u = _u.SetParentID(*id)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetParent sets the "parent" edge to the Doc entity.
|
||||
func (_u *DocUpdateOne) SetParent(v *Doc) *DocUpdateOne {
|
||||
return _u.SetParentID(v.ID)
|
||||
}
|
||||
|
||||
// AddChildIDs adds the "children" edge to the Doc entity by IDs.
|
||||
func (_u *DocUpdateOne) AddChildIDs(ids ...schema.DocID) *DocUpdateOne {
|
||||
_u.mutation.AddChildIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddChildren adds the "children" edges to the Doc entity.
|
||||
func (_u *DocUpdateOne) AddChildren(v ...*Doc) *DocUpdateOne {
|
||||
ids := make([]schema.DocID, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddChildIDs(ids...)
|
||||
}
|
||||
|
||||
// AddRelatedIDs adds the "related" edge to the Doc entity by IDs.
|
||||
func (_u *DocUpdateOne) AddRelatedIDs(ids ...schema.DocID) *DocUpdateOne {
|
||||
_u.mutation.AddRelatedIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddRelated adds the "related" edges to the Doc entity.
|
||||
func (_u *DocUpdateOne) AddRelated(v ...*Doc) *DocUpdateOne {
|
||||
ids := make([]schema.DocID, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddRelatedIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the DocMutation object of the builder.
|
||||
func (_u *DocUpdateOne) Mutation() *DocMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearParent clears the "parent" edge to the Doc entity.
|
||||
func (_u *DocUpdateOne) ClearParent() *DocUpdateOne {
|
||||
_u.mutation.ClearParent()
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearChildren clears all "children" edges to the Doc entity.
|
||||
func (_u *DocUpdateOne) ClearChildren() *DocUpdateOne {
|
||||
_u.mutation.ClearChildren()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveChildIDs removes the "children" edge to Doc entities by IDs.
|
||||
func (_u *DocUpdateOne) RemoveChildIDs(ids ...schema.DocID) *DocUpdateOne {
|
||||
_u.mutation.RemoveChildIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveChildren removes "children" edges to Doc entities.
|
||||
func (_u *DocUpdateOne) RemoveChildren(v ...*Doc) *DocUpdateOne {
|
||||
ids := make([]schema.DocID, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveChildIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearRelated clears all "related" edges to the Doc entity.
|
||||
func (_u *DocUpdateOne) ClearRelated() *DocUpdateOne {
|
||||
_u.mutation.ClearRelated()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveRelatedIDs removes the "related" edge to Doc entities by IDs.
|
||||
func (_u *DocUpdateOne) RemoveRelatedIDs(ids ...schema.DocID) *DocUpdateOne {
|
||||
_u.mutation.RemoveRelatedIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveRelated removes "related" edges to Doc entities.
|
||||
func (_u *DocUpdateOne) RemoveRelated(v ...*Doc) *DocUpdateOne {
|
||||
ids := make([]schema.DocID, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveRelatedIDs(ids...)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the DocUpdate builder.
|
||||
func (_u *DocUpdateOne) Where(ps ...predicate.Doc) *DocUpdateOne {
|
||||
_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 *DocUpdateOne) Select(field string, fields ...string) *DocUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Doc entity.
|
||||
func (_u *DocUpdateOne) Save(ctx context.Context) (*Doc, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *DocUpdateOne) SaveX(ctx context.Context) *Doc {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *DocUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *DocUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *DocUpdateOne) sqlSave(ctx context.Context) (_node *Doc, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(doc.Table, doc.Columns, sqlgraph.NewFieldSpec(doc.FieldID, field.TypeString))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Doc.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, doc.FieldID)
|
||||
for _, f := range fields {
|
||||
if !doc.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != doc.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.Text(); ok {
|
||||
_spec.SetField(doc.FieldText, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.TextCleared() {
|
||||
_spec.ClearField(doc.FieldText, field.TypeString)
|
||||
}
|
||||
if _u.mutation.ParentCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: doc.ParentTable,
|
||||
Columns: []string{doc.ParentColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(doc.FieldID, field.TypeString),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.ParentIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: doc.ParentTable,
|
||||
Columns: []string{doc.ParentColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(doc.FieldID, field.TypeString),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _u.mutation.ChildrenCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: doc.ChildrenTable,
|
||||
Columns: []string{doc.ChildrenColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(doc.FieldID, field.TypeString),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedChildrenIDs(); len(nodes) > 0 && !_u.mutation.ChildrenCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: doc.ChildrenTable,
|
||||
Columns: []string{doc.ChildrenColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(doc.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.ChildrenIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: doc.ChildrenTable,
|
||||
Columns: []string{doc.ChildrenColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(doc.FieldID, field.TypeString),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _u.mutation.RelatedCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: doc.RelatedTable,
|
||||
Columns: doc.RelatedPrimaryKey,
|
||||
Bidi: true,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(doc.FieldID, field.TypeString),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedRelatedIDs(); len(nodes) > 0 && !_u.mutation.RelatedCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: doc.RelatedTable,
|
||||
Columns: doc.RelatedPrimaryKey,
|
||||
Bidi: true,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(doc.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.RelatedIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: doc.RelatedTable,
|
||||
Columns: doc.RelatedPrimaryKey,
|
||||
Bidi: true,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(doc.FieldID, field.TypeString),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &Doc{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{doc.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
Reference in New Issue
Block a user