mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/gen: use a set when tracking cleared fields in mutation template
Signed-off-by: Alex Snast <alexsn@fb.com>
This commit is contained in:
@@ -75,8 +75,8 @@ func (cc *CardCreate) Save(ctx context.Context) (*Card, 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 *CardDelete) 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
|
||||
|
||||
@@ -85,8 +85,8 @@ func (cu *CardUpdate) 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
|
||||
@@ -253,8 +253,8 @@ func (cuo *CardUpdateOne) Save(ctx context.Context) (*Card, 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
|
||||
|
||||
@@ -38,7 +38,7 @@ type CardMutation struct {
|
||||
id *int
|
||||
expired *time.Time
|
||||
number *string
|
||||
clearedFields map[string]bool
|
||||
clearedFields map[string]struct{}
|
||||
owner *int
|
||||
clearedowner bool
|
||||
}
|
||||
@@ -51,7 +51,7 @@ func newCardMutation(c config, op Op) *CardMutation {
|
||||
config: c,
|
||||
op: op,
|
||||
typ: TypeCard,
|
||||
clearedFields: make(map[string]bool),
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,7 +251,8 @@ func (m *CardMutation) ClearedFields() []string {
|
||||
// FieldCleared returns a boolean indicates if this field was
|
||||
// cleared in this mutation.
|
||||
func (m *CardMutation) 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 UserMutation struct {
|
||||
age *int
|
||||
addage *int
|
||||
name *string
|
||||
clearedFields map[string]bool
|
||||
clearedFields map[string]struct{}
|
||||
card *int
|
||||
clearedcard bool
|
||||
}
|
||||
@@ -378,7 +379,7 @@ func newUserMutation(c config, op Op) *UserMutation {
|
||||
config: c,
|
||||
op: op,
|
||||
typ: TypeUser,
|
||||
clearedFields: make(map[string]bool),
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -613,7 +614,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
|
||||
|
||||
@@ -79,8 +79,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
|
||||
|
||||
@@ -95,8 +95,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
|
||||
@@ -282,8 +282,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