mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/gen: move predicates to mutation object (#825)
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/facebook/ent/examples/m2mbidi/ent/predicate"
|
||||
"github.com/facebook/ent/examples/m2mbidi/ent/user"
|
||||
|
||||
"github.com/facebook/ent"
|
||||
@@ -44,6 +45,7 @@ type UserMutation struct {
|
||||
clearedfriends bool
|
||||
done bool
|
||||
oldValue func(context.Context) (*User, error)
|
||||
predicates []predicate.User
|
||||
}
|
||||
|
||||
var _ ent.Mutation = (*UserMutation)(nil)
|
||||
|
||||
@@ -20,14 +20,13 @@ import (
|
||||
// UserDelete is the builder for deleting a User entity.
|
||||
type UserDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *UserMutation
|
||||
predicates []predicate.User
|
||||
hooks []Hook
|
||||
mutation *UserMutation
|
||||
}
|
||||
|
||||
// Where adds a new predicate to the delete builder.
|
||||
func (ud *UserDelete) Where(ps ...predicate.User) *UserDelete {
|
||||
ud.predicates = append(ud.predicates, ps...)
|
||||
ud.mutation.predicates = append(ud.mutation.predicates, ps...)
|
||||
return ud
|
||||
}
|
||||
|
||||
@@ -79,7 +78,7 @@ func (ud *UserDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
},
|
||||
},
|
||||
}
|
||||
if ps := ud.predicates; len(ps) > 0 {
|
||||
if ps := ud.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
|
||||
@@ -20,14 +20,13 @@ import (
|
||||
// UserUpdate is the builder for updating User entities.
|
||||
type UserUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *UserMutation
|
||||
predicates []predicate.User
|
||||
hooks []Hook
|
||||
mutation *UserMutation
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the builder.
|
||||
func (uu *UserUpdate) Where(ps ...predicate.User) *UserUpdate {
|
||||
uu.predicates = append(uu.predicates, ps...)
|
||||
uu.mutation.predicates = append(uu.mutation.predicates, ps...)
|
||||
return uu
|
||||
}
|
||||
|
||||
@@ -153,7 +152,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
},
|
||||
},
|
||||
}
|
||||
if ps := uu.predicates; len(ps) > 0 {
|
||||
if ps := uu.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
|
||||
Reference in New Issue
Block a user