mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/gen: propagate nodes post-save mutations (#2525)
* Failing test * Fix propagating entirely models from OpCreate hook * Apply suggestions from code review Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com> * whitespace * Failing test for updateone * fix for updateone * Regnerate * regen from root Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com>
This commit is contained in:
@@ -95,9 +95,15 @@ func (cc *CarCreate) Save(ctx context.Context) (*Car, error) {
|
||||
}
|
||||
mut = cc.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, cc.mutation); err != nil {
|
||||
v, err := mut.Mutate(ctx, cc.mutation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nv, ok := v.(*Car)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected node type %T returned from CarMutation", v)
|
||||
}
|
||||
node = nv
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
||||
@@ -289,9 +289,15 @@ func (cuo *CarUpdateOne) Save(ctx context.Context) (*Car, error) {
|
||||
}
|
||||
mut = cuo.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, cuo.mutation); err != nil {
|
||||
v, err := mut.Mutate(ctx, cuo.mutation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nv, ok := v.(*Car)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected node type %T returned from CarMutation", v)
|
||||
}
|
||||
node = nv
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
||||
@@ -84,9 +84,15 @@ func (gc *GroupCreate) Save(ctx context.Context) (*Group, error) {
|
||||
}
|
||||
mut = gc.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, gc.mutation); err != nil {
|
||||
v, err := mut.Mutate(ctx, gc.mutation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nv, ok := v.(*Group)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected node type %T returned from GroupMutation", v)
|
||||
}
|
||||
node = nv
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
||||
@@ -332,9 +332,15 @@ func (guo *GroupUpdateOne) Save(ctx context.Context) (*Group, error) {
|
||||
}
|
||||
mut = guo.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, guo.mutation); err != nil {
|
||||
v, err := mut.Mutate(ctx, guo.mutation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nv, ok := v.(*Group)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected node type %T returned from GroupMutation", v)
|
||||
}
|
||||
node = nv
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
||||
@@ -115,9 +115,15 @@ func (uc *UserCreate) Save(ctx context.Context) (*User, error) {
|
||||
}
|
||||
mut = uc.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, uc.mutation); err != nil {
|
||||
v, err := mut.Mutate(ctx, uc.mutation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nv, ok := v.(*User)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected node type %T returned from UserMutation", v)
|
||||
}
|
||||
node = nv
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
||||
@@ -515,9 +515,15 @@ func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) {
|
||||
}
|
||||
mut = uuo.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, uuo.mutation); err != nil {
|
||||
v, err := mut.Mutate(ctx, uuo.mutation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nv, ok := v.(*User)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected node type %T returned from UserMutation", v)
|
||||
}
|
||||
node = nv
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user