MCPcopy
hub / github.com/ent/ent / sqlSave

Method sqlSave

entc/integration/migrate/entv2/blog_update.go:306–396  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

304}
305
306func (_u *BlogUpdateOne) sqlSave(ctx context.Context) (_node *Blog, err error) {
307 _spec := sqlgraph.NewUpdateSpec(blog.Table, blog.Columns, sqlgraph.NewFieldSpec(blog.FieldID, field.TypeInt))
308 id, ok := _u.mutation.ID()
309 if !ok {
310 return nil, &ValidationError{Name: "id", err: errors.New(`entv2: missing "Blog.id" for update`)}
311 }
312 _spec.Node.ID.Value = id
313 if fields := _u.fields; len(fields) > 0 {
314 _spec.Node.Columns = make([]string, 0, len(fields))
315 _spec.Node.Columns = append(_spec.Node.Columns, blog.FieldID)
316 for _, f := range fields {
317 if !blog.ValidColumn(f) {
318 return nil, &ValidationError{Name: f, err: fmt.Errorf("entv2: invalid field %q for query", f)}
319 }
320 if f != blog.FieldID {
321 _spec.Node.Columns = append(_spec.Node.Columns, f)
322 }
323 }
324 }
325 if ps := _u.mutation.predicates; len(ps) > 0 {
326 _spec.Predicate = func(selector *sql.Selector) {
327 for i := range ps {
328 ps[i](selector)
329 }
330 }
331 }
332 if value, ok := _u.mutation.Oid(); ok {
333 _spec.SetField(blog.FieldOid, field.TypeInt, value)
334 }
335 if value, ok := _u.mutation.AddedOid(); ok {
336 _spec.AddField(blog.FieldOid, field.TypeInt, value)
337 }
338 if _u.mutation.AdminsCleared() {
339 edge := &sqlgraph.EdgeSpec{
340 Rel: sqlgraph.O2M,
341 Inverse: false,
342 Table: blog.AdminsTable,
343 Columns: []string{blog.AdminsColumn},
344 Bidi: false,
345 Target: &sqlgraph.EdgeTarget{
346 IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
347 },
348 }
349 _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
350 }
351 if nodes := _u.mutation.RemovedAdminsIDs(); len(nodes) > 0 && !_u.mutation.AdminsCleared() {
352 edge := &sqlgraph.EdgeSpec{
353 Rel: sqlgraph.O2M,
354 Inverse: false,
355 Table: blog.AdminsTable,
356 Columns: []string{blog.AdminsColumn},
357 Bidi: false,
358 Target: &sqlgraph.EdgeTarget{
359 IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
360 },
361 }
362 for _, k := range nodes {
363 edge.Target.Nodes = append(edge.Target.Nodes, k)

Callers

nothing calls this directly

Calls 15

SetFieldMethod · 0.95
AddFieldMethod · 0.95
NewUpdateSpecFunction · 0.92
NewFieldSpecFunction · 0.92
ValidColumnFunction · 0.92
UpdateNodeFunction · 0.92
IsConstraintErrorFunction · 0.92
NewMethod · 0.80
OidMethod · 0.80
AddedOidMethod · 0.80
AdminsClearedMethod · 0.80
RemovedAdminsIDsMethod · 0.80

Tested by

no test coverage detected