mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
all: replace save with exec when the model is not needed
This commit is contained in:
committed by
Ariel Mashraki
parent
7015647528
commit
f0d985f542
@@ -158,7 +158,7 @@ func QueryCarUsers(ctx context.Context, a8m *ent.User) error {
|
||||
}
|
||||
|
||||
func CreateGraph(ctx context.Context, client *ent.Client) error {
|
||||
// first, create the users.
|
||||
// First, create the users.
|
||||
a8m, err := client.User.
|
||||
Create().
|
||||
SetAge(30).
|
||||
@@ -175,48 +175,48 @@ func CreateGraph(ctx context.Context, client *ent.Client) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// then, create the cars, and attach them to the users in the creation.
|
||||
_, err = client.Car.
|
||||
// Then, create the cars, and attach them to the users in the creation.
|
||||
err = client.Car.
|
||||
Create().
|
||||
SetModel("Tesla").
|
||||
SetRegisteredAt(time.Now()). // ignore the time in the graph.
|
||||
SetOwner(a8m). // attach this graph to Ariel.
|
||||
Save(ctx)
|
||||
Exec(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = client.Car.
|
||||
err = client.Car.
|
||||
Create().
|
||||
SetModel("Mazda").
|
||||
SetRegisteredAt(time.Now()). // ignore the time in the graph.
|
||||
SetOwner(a8m). // attach this graph to Ariel.
|
||||
Save(ctx)
|
||||
Exec(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = client.Car.
|
||||
err = client.Car.
|
||||
Create().
|
||||
SetModel("Ford").
|
||||
SetRegisteredAt(time.Now()). // ignore the time in the graph.
|
||||
SetOwner(neta). // attach this graph to Neta.
|
||||
Save(ctx)
|
||||
Exec(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// create the groups, and add their users in the creation.
|
||||
_, err = client.Group.
|
||||
// Create the groups, and add their users in the creation.
|
||||
err = client.Group.
|
||||
Create().
|
||||
SetName("GitLab").
|
||||
AddUsers(neta, a8m).
|
||||
Save(ctx)
|
||||
Exec(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = client.Group.
|
||||
err = client.Group.
|
||||
Create().
|
||||
SetName("GitHub").
|
||||
AddUsers(a8m).
|
||||
Save(ctx)
|
||||
Exec(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user