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

Method sqlSave

entc/integration/migrate/entv2/car_update.go:269–346  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

267}
268
269func (_u *CarUpdateOne) sqlSave(ctx context.Context) (_node *Car, err error) {
270 if err := _u.check(); err != nil {
271 return _node, err
272 }
273 _spec := sqlgraph.NewUpdateSpec(car.Table, car.Columns, sqlgraph.NewFieldSpec(car.FieldID, field.TypeInt))
274 id, ok := _u.mutation.ID()
275 if !ok {
276 return nil, &ValidationError{Name: "id", err: errors.New(`entv2: missing "Car.id" for update`)}
277 }
278 _spec.Node.ID.Value = id
279 if fields := _u.fields; len(fields) > 0 {
280 _spec.Node.Columns = make([]string, 0, len(fields))
281 _spec.Node.Columns = append(_spec.Node.Columns, car.FieldID)
282 for _, f := range fields {
283 if !car.ValidColumn(f) {
284 return nil, &ValidationError{Name: f, err: fmt.Errorf("entv2: invalid field %q for query", f)}
285 }
286 if f != car.FieldID {
287 _spec.Node.Columns = append(_spec.Node.Columns, f)
288 }
289 }
290 }
291 if ps := _u.mutation.predicates; len(ps) > 0 {
292 _spec.Predicate = func(selector *sql.Selector) {
293 for i := range ps {
294 ps[i](selector)
295 }
296 }
297 }
298 if value, ok := _u.mutation.Name(); ok {
299 _spec.SetField(car.FieldName, field.TypeString, value)
300 }
301 if _u.mutation.NameCleared() {
302 _spec.ClearField(car.FieldName, field.TypeString)
303 }
304 if _u.mutation.OwnerCleared() {
305 edge := &sqlgraph.EdgeSpec{
306 Rel: sqlgraph.M2O,
307 Inverse: true,
308 Table: car.OwnerTable,
309 Columns: []string{car.OwnerColumn},
310 Bidi: false,
311 Target: &sqlgraph.EdgeTarget{
312 IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
313 },
314 }
315 _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
316 }
317 if nodes := _u.mutation.OwnerIDs(); len(nodes) > 0 {
318 edge := &sqlgraph.EdgeSpec{
319 Rel: sqlgraph.M2O,
320 Inverse: true,
321 Table: car.OwnerTable,
322 Columns: []string{car.OwnerColumn},
323 Bidi: false,
324 Target: &sqlgraph.EdgeTarget{
325 IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
326 },

Callers

nothing calls this directly

Calls 15

checkMethod · 0.95
SetFieldMethod · 0.95
ClearFieldMethod · 0.95
NewUpdateSpecFunction · 0.92
NewFieldSpecFunction · 0.92
ValidColumnFunction · 0.92
UpdateNodeFunction · 0.92
IsConstraintErrorFunction · 0.92
NewMethod · 0.80
NameMethod · 0.65
ErrorMethod · 0.65
IDMethod · 0.45

Tested by

no test coverage detected