mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/gen: support de/incrementing values on upsert
Fixed https://github.com/ent/ent/issues/1952.
This commit is contained in:
committed by
Ariel Mashraki
parent
8cb468f979
commit
5f31091dcd
@@ -297,9 +297,20 @@ func Upsert(t *testing.T, client *ent.Client) {
|
||||
require.Equal(t, u.ID, id)
|
||||
u = client.User.GetX(ctx, u.ID)
|
||||
require.Equal(t, "Mashraki", u.Name)
|
||||
require.Equal(t, 33, u.Age, "address was modified by the UPDATE clause")
|
||||
require.Equal(t, 33, u.Age, "age was modified by the UPDATE clause")
|
||||
require.Equal(t, "localhost", u.Address, "address was modified by the UPDATE clause")
|
||||
|
||||
id = client.User.Create().
|
||||
SetName("Boring").
|
||||
SetAge(33).
|
||||
SetPhone("0000").
|
||||
OnConflictColumns(user.FieldPhone).
|
||||
// Override some of the fields with custom update.
|
||||
AddAge(-1).
|
||||
IDX(ctx)
|
||||
u = client.User.GetX(ctx, id)
|
||||
require.Equal(t, 32, u.Age, "age was modified by the UPDATE clause")
|
||||
|
||||
builders := []*ent.UserCreate{
|
||||
client.User.Create().SetName("A").SetAge(1).SetPhone("0000"), // Duplicate
|
||||
client.User.Create().SetName("B").SetAge(1).SetPhone("1111"), // New row.
|
||||
|
||||
Reference in New Issue
Block a user