mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
Merge pull request #392 from facebookincubator/mutset
entc/gen: use a set when tracking cleared fields in mutation template
This commit is contained in:
@@ -80,8 +80,8 @@ func (cc *CarCreate) Save(ctx context.Context) (*Car, error) {
|
||||
node, err = cc.sqlSave(ctx)
|
||||
return node, err
|
||||
})
|
||||
for i := len(cc.hooks); i > 0; i-- {
|
||||
mut = cc.hooks[i-1](mut)
|
||||
for i := len(cc.hooks) - 1; i >= 0; i-- {
|
||||
mut = cc.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, cc.mutation); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -49,8 +49,8 @@ func (cd *CarDelete) Exec(ctx context.Context) (int, error) {
|
||||
affected, err = cd.sqlExec(ctx)
|
||||
return affected, err
|
||||
})
|
||||
for i := len(cd.hooks); i > 0; i-- {
|
||||
mut = cd.hooks[i-1](mut)
|
||||
for i := len(cd.hooks) - 1; i >= 0; i-- {
|
||||
mut = cd.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, cd.mutation); err != nil {
|
||||
return 0, err
|
||||
|
||||
@@ -89,8 +89,8 @@ func (cu *CarUpdate) Save(ctx context.Context) (int, error) {
|
||||
affected, err = cu.sqlSave(ctx)
|
||||
return affected, err
|
||||
})
|
||||
for i := len(cu.hooks); i > 0; i-- {
|
||||
mut = cu.hooks[i-1](mut)
|
||||
for i := len(cu.hooks) - 1; i >= 0; i-- {
|
||||
mut = cu.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, cu.mutation); err != nil {
|
||||
return 0, err
|
||||
@@ -262,8 +262,8 @@ func (cuo *CarUpdateOne) Save(ctx context.Context) (*Car, error) {
|
||||
node, err = cuo.sqlSave(ctx)
|
||||
return node, err
|
||||
})
|
||||
for i := len(cuo.hooks); i > 0; i-- {
|
||||
mut = cuo.hooks[i-1](mut)
|
||||
for i := len(cuo.hooks) - 1; i >= 0; i-- {
|
||||
mut = cuo.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, cuo.mutation); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -71,8 +71,8 @@ func (gc *GroupCreate) Save(ctx context.Context) (*Group, error) {
|
||||
node, err = gc.sqlSave(ctx)
|
||||
return node, err
|
||||
})
|
||||
for i := len(gc.hooks); i > 0; i-- {
|
||||
mut = gc.hooks[i-1](mut)
|
||||
for i := len(gc.hooks) - 1; i >= 0; i-- {
|
||||
mut = gc.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, gc.mutation); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -49,8 +49,8 @@ func (gd *GroupDelete) Exec(ctx context.Context) (int, error) {
|
||||
affected, err = gd.sqlExec(ctx)
|
||||
return affected, err
|
||||
})
|
||||
for i := len(gd.hooks); i > 0; i-- {
|
||||
mut = gd.hooks[i-1](mut)
|
||||
for i := len(gd.hooks) - 1; i >= 0; i-- {
|
||||
mut = gd.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, gd.mutation); err != nil {
|
||||
return 0, err
|
||||
|
||||
@@ -92,8 +92,8 @@ func (gu *GroupUpdate) Save(ctx context.Context) (int, error) {
|
||||
affected, err = gu.sqlSave(ctx)
|
||||
return affected, err
|
||||
})
|
||||
for i := len(gu.hooks); i > 0; i-- {
|
||||
mut = gu.hooks[i-1](mut)
|
||||
for i := len(gu.hooks) - 1; i >= 0; i-- {
|
||||
mut = gu.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, gu.mutation); err != nil {
|
||||
return 0, err
|
||||
@@ -265,8 +265,8 @@ func (guo *GroupUpdateOne) Save(ctx context.Context) (*Group, error) {
|
||||
node, err = guo.sqlSave(ctx)
|
||||
return node, err
|
||||
})
|
||||
for i := len(guo.hooks); i > 0; i-- {
|
||||
mut = guo.hooks[i-1](mut)
|
||||
for i := len(guo.hooks) - 1; i >= 0; i-- {
|
||||
mut = guo.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, guo.mutation); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -40,7 +40,7 @@ type CarMutation struct {
|
||||
id *int
|
||||
model *string
|
||||
registered_at *time.Time
|
||||
clearedFields map[string]bool
|
||||
clearedFields map[string]struct{}
|
||||
owner *int
|
||||
clearedowner bool
|
||||
}
|
||||
@@ -53,7 +53,7 @@ func newCarMutation(c config, op Op) *CarMutation {
|
||||
config: c,
|
||||
op: op,
|
||||
typ: TypeCar,
|
||||
clearedFields: make(map[string]bool),
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,7 +253,8 @@ func (m *CarMutation) ClearedFields() []string {
|
||||
// FieldCleared returns a boolean indicates if this field was
|
||||
// cleared in this mutation.
|
||||
func (m *CarMutation) FieldCleared(name string) bool {
|
||||
return m.clearedFields[name]
|
||||
_, ok := m.clearedFields[name]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ClearField clears the value for the given name. It returns an
|
||||
@@ -365,7 +366,7 @@ type GroupMutation struct {
|
||||
typ string
|
||||
id *int
|
||||
name *string
|
||||
clearedFields map[string]bool
|
||||
clearedFields map[string]struct{}
|
||||
users map[int]struct{}
|
||||
removedusers map[int]struct{}
|
||||
}
|
||||
@@ -378,7 +379,7 @@ func newGroupMutation(c config, op Op) *GroupMutation {
|
||||
config: c,
|
||||
op: op,
|
||||
typ: TypeGroup,
|
||||
clearedFields: make(map[string]bool),
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -550,7 +551,8 @@ func (m *GroupMutation) ClearedFields() []string {
|
||||
// FieldCleared returns a boolean indicates if this field was
|
||||
// cleared in this mutation.
|
||||
func (m *GroupMutation) FieldCleared(name string) bool {
|
||||
return m.clearedFields[name]
|
||||
_, ok := m.clearedFields[name]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ClearField clears the value for the given name. It returns an
|
||||
@@ -664,7 +666,7 @@ type UserMutation struct {
|
||||
age *int
|
||||
addage *int
|
||||
name *string
|
||||
clearedFields map[string]bool
|
||||
clearedFields map[string]struct{}
|
||||
cars map[int]struct{}
|
||||
removedcars map[int]struct{}
|
||||
groups map[int]struct{}
|
||||
@@ -679,7 +681,7 @@ func newUserMutation(c config, op Op) *UserMutation {
|
||||
config: c,
|
||||
op: op,
|
||||
typ: TypeUser,
|
||||
clearedFields: make(map[string]bool),
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -959,7 +961,8 @@ func (m *UserMutation) ClearedFields() []string {
|
||||
// FieldCleared returns a boolean indicates if this field was
|
||||
// cleared in this mutation.
|
||||
func (m *UserMutation) FieldCleared(name string) bool {
|
||||
return m.clearedFields[name]
|
||||
_, ok := m.clearedFields[name]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ClearField clears the value for the given name. It returns an
|
||||
|
||||
@@ -105,8 +105,8 @@ func (uc *UserCreate) Save(ctx context.Context) (*User, error) {
|
||||
node, err = uc.sqlSave(ctx)
|
||||
return node, err
|
||||
})
|
||||
for i := len(uc.hooks); i > 0; i-- {
|
||||
mut = uc.hooks[i-1](mut)
|
||||
for i := len(uc.hooks) - 1; i >= 0; i-- {
|
||||
mut = uc.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, uc.mutation); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -49,8 +49,8 @@ func (ud *UserDelete) Exec(ctx context.Context) (int, error) {
|
||||
affected, err = ud.sqlExec(ctx)
|
||||
return affected, err
|
||||
})
|
||||
for i := len(ud.hooks); i > 0; i-- {
|
||||
mut = ud.hooks[i-1](mut)
|
||||
for i := len(ud.hooks) - 1; i >= 0; i-- {
|
||||
mut = ud.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, ud.mutation); err != nil {
|
||||
return 0, err
|
||||
|
||||
@@ -144,8 +144,8 @@ func (uu *UserUpdate) Save(ctx context.Context) (int, error) {
|
||||
affected, err = uu.sqlSave(ctx)
|
||||
return affected, err
|
||||
})
|
||||
for i := len(uu.hooks); i > 0; i-- {
|
||||
mut = uu.hooks[i-1](mut)
|
||||
for i := len(uu.hooks) - 1; i >= 0; i-- {
|
||||
mut = uu.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, uu.mutation); err != nil {
|
||||
return 0, err
|
||||
@@ -420,8 +420,8 @@ func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) {
|
||||
node, err = uuo.sqlSave(ctx)
|
||||
return node, err
|
||||
})
|
||||
for i := len(uuo.hooks); i > 0; i-- {
|
||||
mut = uuo.hooks[i-1](mut)
|
||||
for i := len(uuo.hooks) - 1; i >= 0; i-- {
|
||||
mut = uuo.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, uuo.mutation); err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user