mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/gen/template: remove receiver conflict handling logic (#4356)
* examples: ensure tests is stable * entc/gen/template: remove receiver conflict handling logic * examples: codegen * entc/integration: codegen
This commit is contained in:
@@ -25,8 +25,8 @@ type GroupCreate struct {
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_c *GroupCreate) SetName(s string) *GroupCreate {
|
||||
_c.mutation.SetName(s)
|
||||
func (_c *GroupCreate) SetName(v string) *GroupCreate {
|
||||
_c.mutation.SetName(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
@@ -37,10 +37,10 @@ func (_c *GroupCreate) AddUserIDs(ids ...int) *GroupCreate {
|
||||
}
|
||||
|
||||
// AddUsers adds the "users" edges to the User entity.
|
||||
func (_c *GroupCreate) AddUsers(u ...*User) *GroupCreate {
|
||||
ids := make([]int, len(u))
|
||||
for i := range u {
|
||||
ids[i] = u[i].ID
|
||||
func (_c *GroupCreate) AddUsers(v ...*User) *GroupCreate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _c.AddUserIDs(ids...)
|
||||
}
|
||||
|
||||
@@ -33,15 +33,15 @@ func (_u *GroupUpdate) Where(ps ...predicate.Group) *GroupUpdate {
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_u *GroupUpdate) SetName(s string) *GroupUpdate {
|
||||
_u.mutation.SetName(s)
|
||||
func (_u *GroupUpdate) SetName(v string) *GroupUpdate {
|
||||
_u.mutation.SetName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_u *GroupUpdate) SetNillableName(s *string) *GroupUpdate {
|
||||
if s != nil {
|
||||
_u.SetName(*s)
|
||||
func (_u *GroupUpdate) SetNillableName(v *string) *GroupUpdate {
|
||||
if v != nil {
|
||||
_u.SetName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
@@ -53,10 +53,10 @@ func (_u *GroupUpdate) AddUserIDs(ids ...int) *GroupUpdate {
|
||||
}
|
||||
|
||||
// AddUsers adds the "users" edges to the User entity.
|
||||
func (_u *GroupUpdate) AddUsers(u ...*User) *GroupUpdate {
|
||||
ids := make([]int, len(u))
|
||||
for i := range u {
|
||||
ids[i] = u[i].ID
|
||||
func (_u *GroupUpdate) AddUsers(v ...*User) *GroupUpdate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddUserIDs(ids...)
|
||||
}
|
||||
@@ -79,10 +79,10 @@ func (_u *GroupUpdate) RemoveUserIDs(ids ...int) *GroupUpdate {
|
||||
}
|
||||
|
||||
// RemoveUsers removes "users" edges to User entities.
|
||||
func (_u *GroupUpdate) RemoveUsers(u ...*User) *GroupUpdate {
|
||||
ids := make([]int, len(u))
|
||||
for i := range u {
|
||||
ids[i] = u[i].ID
|
||||
func (_u *GroupUpdate) RemoveUsers(v ...*User) *GroupUpdate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveUserIDs(ids...)
|
||||
}
|
||||
@@ -114,7 +114,7 @@ func (_u *GroupUpdate) ExecX(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
func (_u *GroupUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(group.Table, group.Columns, sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt))
|
||||
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
@@ -171,7 +171,7 @@ func (_u *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{group.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
@@ -180,7 +180,7 @@ func (_u *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return n, nil
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// GroupUpdateOne is the builder for updating a single Group entity.
|
||||
@@ -192,15 +192,15 @@ type GroupUpdateOne struct {
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_u *GroupUpdateOne) SetName(s string) *GroupUpdateOne {
|
||||
_u.mutation.SetName(s)
|
||||
func (_u *GroupUpdateOne) SetName(v string) *GroupUpdateOne {
|
||||
_u.mutation.SetName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_u *GroupUpdateOne) SetNillableName(s *string) *GroupUpdateOne {
|
||||
if s != nil {
|
||||
_u.SetName(*s)
|
||||
func (_u *GroupUpdateOne) SetNillableName(v *string) *GroupUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
@@ -212,10 +212,10 @@ func (_u *GroupUpdateOne) AddUserIDs(ids ...int) *GroupUpdateOne {
|
||||
}
|
||||
|
||||
// AddUsers adds the "users" edges to the User entity.
|
||||
func (_u *GroupUpdateOne) AddUsers(u ...*User) *GroupUpdateOne {
|
||||
ids := make([]int, len(u))
|
||||
for i := range u {
|
||||
ids[i] = u[i].ID
|
||||
func (_u *GroupUpdateOne) AddUsers(v ...*User) *GroupUpdateOne {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddUserIDs(ids...)
|
||||
}
|
||||
@@ -238,10 +238,10 @@ func (_u *GroupUpdateOne) RemoveUserIDs(ids ...int) *GroupUpdateOne {
|
||||
}
|
||||
|
||||
// RemoveUsers removes "users" edges to User entities.
|
||||
func (_u *GroupUpdateOne) RemoveUsers(u ...*User) *GroupUpdateOne {
|
||||
ids := make([]int, len(u))
|
||||
for i := range u {
|
||||
ids[i] = u[i].ID
|
||||
func (_u *GroupUpdateOne) RemoveUsers(v ...*User) *GroupUpdateOne {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveUserIDs(ids...)
|
||||
}
|
||||
|
||||
@@ -25,14 +25,14 @@ type UserCreate struct {
|
||||
}
|
||||
|
||||
// SetAge sets the "age" field.
|
||||
func (_c *UserCreate) SetAge(i int) *UserCreate {
|
||||
_c.mutation.SetAge(i)
|
||||
func (_c *UserCreate) SetAge(v int) *UserCreate {
|
||||
_c.mutation.SetAge(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_c *UserCreate) SetName(s string) *UserCreate {
|
||||
_c.mutation.SetName(s)
|
||||
func (_c *UserCreate) SetName(v string) *UserCreate {
|
||||
_c.mutation.SetName(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
@@ -43,10 +43,10 @@ func (_c *UserCreate) AddGroupIDs(ids ...int) *UserCreate {
|
||||
}
|
||||
|
||||
// AddGroups adds the "groups" edges to the Group entity.
|
||||
func (_c *UserCreate) AddGroups(g ...*Group) *UserCreate {
|
||||
ids := make([]int, len(g))
|
||||
for i := range g {
|
||||
ids[i] = g[i].ID
|
||||
func (_c *UserCreate) AddGroups(v ...*Group) *UserCreate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _c.AddGroupIDs(ids...)
|
||||
}
|
||||
|
||||
@@ -33,36 +33,36 @@ func (_u *UserUpdate) Where(ps ...predicate.User) *UserUpdate {
|
||||
}
|
||||
|
||||
// SetAge sets the "age" field.
|
||||
func (_u *UserUpdate) SetAge(i int) *UserUpdate {
|
||||
func (_u *UserUpdate) SetAge(v int) *UserUpdate {
|
||||
_u.mutation.ResetAge()
|
||||
_u.mutation.SetAge(i)
|
||||
_u.mutation.SetAge(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableAge sets the "age" field if the given value is not nil.
|
||||
func (_u *UserUpdate) SetNillableAge(i *int) *UserUpdate {
|
||||
if i != nil {
|
||||
_u.SetAge(*i)
|
||||
func (_u *UserUpdate) SetNillableAge(v *int) *UserUpdate {
|
||||
if v != nil {
|
||||
_u.SetAge(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddAge adds i to the "age" field.
|
||||
func (_u *UserUpdate) AddAge(i int) *UserUpdate {
|
||||
_u.mutation.AddAge(i)
|
||||
// AddAge adds value to the "age" field.
|
||||
func (_u *UserUpdate) AddAge(v int) *UserUpdate {
|
||||
_u.mutation.AddAge(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_u *UserUpdate) SetName(s string) *UserUpdate {
|
||||
_u.mutation.SetName(s)
|
||||
func (_u *UserUpdate) SetName(v string) *UserUpdate {
|
||||
_u.mutation.SetName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_u *UserUpdate) SetNillableName(s *string) *UserUpdate {
|
||||
if s != nil {
|
||||
_u.SetName(*s)
|
||||
func (_u *UserUpdate) SetNillableName(v *string) *UserUpdate {
|
||||
if v != nil {
|
||||
_u.SetName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
@@ -74,10 +74,10 @@ func (_u *UserUpdate) AddGroupIDs(ids ...int) *UserUpdate {
|
||||
}
|
||||
|
||||
// AddGroups adds the "groups" edges to the Group entity.
|
||||
func (_u *UserUpdate) AddGroups(g ...*Group) *UserUpdate {
|
||||
ids := make([]int, len(g))
|
||||
for i := range g {
|
||||
ids[i] = g[i].ID
|
||||
func (_u *UserUpdate) AddGroups(v ...*Group) *UserUpdate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddGroupIDs(ids...)
|
||||
}
|
||||
@@ -100,10 +100,10 @@ func (_u *UserUpdate) RemoveGroupIDs(ids ...int) *UserUpdate {
|
||||
}
|
||||
|
||||
// RemoveGroups removes "groups" edges to Group entities.
|
||||
func (_u *UserUpdate) RemoveGroups(g ...*Group) *UserUpdate {
|
||||
ids := make([]int, len(g))
|
||||
for i := range g {
|
||||
ids[i] = g[i].ID
|
||||
func (_u *UserUpdate) RemoveGroups(v ...*Group) *UserUpdate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveGroupIDs(ids...)
|
||||
}
|
||||
@@ -135,7 +135,7 @@ func (_u *UserUpdate) ExecX(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
|
||||
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
@@ -198,7 +198,7 @@ func (_u *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{user.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
@@ -207,7 +207,7 @@ func (_u *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return n, nil
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// UserUpdateOne is the builder for updating a single User entity.
|
||||
@@ -219,36 +219,36 @@ type UserUpdateOne struct {
|
||||
}
|
||||
|
||||
// SetAge sets the "age" field.
|
||||
func (_u *UserUpdateOne) SetAge(i int) *UserUpdateOne {
|
||||
func (_u *UserUpdateOne) SetAge(v int) *UserUpdateOne {
|
||||
_u.mutation.ResetAge()
|
||||
_u.mutation.SetAge(i)
|
||||
_u.mutation.SetAge(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableAge sets the "age" field if the given value is not nil.
|
||||
func (_u *UserUpdateOne) SetNillableAge(i *int) *UserUpdateOne {
|
||||
if i != nil {
|
||||
_u.SetAge(*i)
|
||||
func (_u *UserUpdateOne) SetNillableAge(v *int) *UserUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetAge(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddAge adds i to the "age" field.
|
||||
func (_u *UserUpdateOne) AddAge(i int) *UserUpdateOne {
|
||||
_u.mutation.AddAge(i)
|
||||
// AddAge adds value to the "age" field.
|
||||
func (_u *UserUpdateOne) AddAge(v int) *UserUpdateOne {
|
||||
_u.mutation.AddAge(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_u *UserUpdateOne) SetName(s string) *UserUpdateOne {
|
||||
_u.mutation.SetName(s)
|
||||
func (_u *UserUpdateOne) SetName(v string) *UserUpdateOne {
|
||||
_u.mutation.SetName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_u *UserUpdateOne) SetNillableName(s *string) *UserUpdateOne {
|
||||
if s != nil {
|
||||
_u.SetName(*s)
|
||||
func (_u *UserUpdateOne) SetNillableName(v *string) *UserUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
@@ -260,10 +260,10 @@ func (_u *UserUpdateOne) AddGroupIDs(ids ...int) *UserUpdateOne {
|
||||
}
|
||||
|
||||
// AddGroups adds the "groups" edges to the Group entity.
|
||||
func (_u *UserUpdateOne) AddGroups(g ...*Group) *UserUpdateOne {
|
||||
ids := make([]int, len(g))
|
||||
for i := range g {
|
||||
ids[i] = g[i].ID
|
||||
func (_u *UserUpdateOne) AddGroups(v ...*Group) *UserUpdateOne {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddGroupIDs(ids...)
|
||||
}
|
||||
@@ -286,10 +286,10 @@ func (_u *UserUpdateOne) RemoveGroupIDs(ids ...int) *UserUpdateOne {
|
||||
}
|
||||
|
||||
// RemoveGroups removes "groups" edges to Group entities.
|
||||
func (_u *UserUpdateOne) RemoveGroups(g ...*Group) *UserUpdateOne {
|
||||
ids := make([]int, len(g))
|
||||
for i := range g {
|
||||
ids[i] = g[i].ID
|
||||
func (_u *UserUpdateOne) RemoveGroups(v ...*Group) *UserUpdateOne {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveGroupIDs(ids...)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"slices"
|
||||
|
||||
"entgo.io/ent/examples/m2m2types/ent"
|
||||
"entgo.io/ent/examples/m2m2types/ent/group"
|
||||
@@ -66,6 +67,9 @@ func Do(ctx context.Context, client *ent.Client) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("querying a8m groups: %w", err)
|
||||
}
|
||||
slices.SortStableFunc(groups, func(i, j *ent.Group) int {
|
||||
return i.ID - j.ID
|
||||
})
|
||||
fmt.Println(groups)
|
||||
// Output: [Group(id=1, name=GitHub) Group(id=2, name=GitLab)]
|
||||
|
||||
@@ -89,6 +93,9 @@ func Do(ctx context.Context, client *ent.Client) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("traversing the graph: %w", err)
|
||||
}
|
||||
slices.SortStableFunc(users, func(i, j *ent.User) int {
|
||||
return i.ID - j.ID
|
||||
})
|
||||
fmt.Println(users)
|
||||
// Output: [User(id=1, age=30, name=a8m) User(id=2, age=28, name=nati)]
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user