mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
Ensure SchemaConfig is set in sqlQuery's context (#1203)
This commit is contained in:
committed by
Ariel Mashraki
parent
aeb1ccc571
commit
bdd8f2f624
File diff suppressed because one or more lines are too long
@@ -130,6 +130,8 @@ func NewSchemaConfigContext(parent context.Context, config SchemaConfig) context
|
||||
{{- $receiver := receiver $builder }}
|
||||
{{- if $.FeatureEnabled "sql/schemaconfig" }}
|
||||
t1.Schema({{ $receiver }}.schemaConfig.{{ $.Name }})
|
||||
ctx = internal.NewSchemaConfigContext(ctx, {{ $receiver }}.schemaConfig)
|
||||
selector.WithContext(ctx)
|
||||
{{- end }}
|
||||
{{- end -}}
|
||||
|
||||
|
||||
@@ -511,6 +511,8 @@ func (gq *GroupQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
selector.Select(selector.Columns(group.Columns...)...)
|
||||
}
|
||||
t1.Schema(gq.schemaConfig.Group)
|
||||
ctx = internal.NewSchemaConfigContext(ctx, gq.schemaConfig)
|
||||
selector.WithContext(ctx)
|
||||
for _, p := range gq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
|
||||
@@ -478,6 +478,8 @@ func (pq *PetQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
selector.Select(selector.Columns(pet.Columns...)...)
|
||||
}
|
||||
t1.Schema(pq.schemaConfig.Pet)
|
||||
ctx = internal.NewSchemaConfigContext(ctx, pq.schemaConfig)
|
||||
selector.WithContext(ctx)
|
||||
for _, p := range pq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
|
||||
@@ -580,6 +580,8 @@ func (uq *UserQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
selector.Select(selector.Columns(user.Columns...)...)
|
||||
}
|
||||
t1.Schema(uq.schemaConfig.User)
|
||||
ctx = internal.NewSchemaConfigContext(ctx, uq.schemaConfig)
|
||||
selector.WithContext(ctx)
|
||||
for _, p := range uq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
|
||||
@@ -12,7 +12,9 @@ import (
|
||||
"github.com/facebook/ent/dialect"
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/facebook/ent/entc/integration/multischema/ent"
|
||||
"github.com/facebook/ent/entc/integration/multischema/ent/group"
|
||||
"github.com/facebook/ent/entc/integration/multischema/ent/migrate"
|
||||
"github.com/facebook/ent/entc/integration/multischema/ent/user"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
@@ -42,12 +44,15 @@ func TestMySQL(t *testing.T) {
|
||||
client.Group.Create().SetName("GitHub"),
|
||||
client.Group.Create().SetName("GitLab"),
|
||||
).SaveX(ctx)
|
||||
client.User.Create().AddPets(pedro).AddGroups(groups...).SaveX(ctx)
|
||||
usr := client.User.Create().AddPets(pedro).AddGroups(groups...).SaveX(ctx)
|
||||
|
||||
// id := client.Group.Query().
|
||||
// Where(group.HasUsersWith(user.ID(usr.ID))).
|
||||
// OnlyIDX(ctx)
|
||||
// require.Equal(t, pedro.ID, id)
|
||||
id := client.Group.Query().
|
||||
Where(group.HasUsersWith(user.ID(usr.ID))).
|
||||
Limit(1).
|
||||
QueryUsers().
|
||||
QueryPets().
|
||||
OnlyIDX(ctx)
|
||||
require.Equal(t, pedro.ID, id)
|
||||
}
|
||||
|
||||
func setupSchema(t *testing.T, drv *sql.Driver) {
|
||||
|
||||
Reference in New Issue
Block a user