mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
dialect/sqlgraph: fix neighbors check with predicates
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/206 Reviewed By: alexsn Differential Revision: D18729641 fbshipit-source-id: a5d333132ae276691ac8c1b084bc5d2037112529
This commit is contained in:
committed by
Facebook Github Bot
parent
29c7b0a0d8
commit
5610d0ade9
@@ -400,6 +400,26 @@ WHERE "groups"."id" IN
|
||||
JOIN "users" AS "t0" ON "user_groups"."user_id" = "t0"."id" WHERE "name" = $1)`,
|
||||
wantArgs: []interface{}{"a8m"},
|
||||
},
|
||||
{
|
||||
name: "M2M/inverse",
|
||||
step: NewStep(
|
||||
From("groups", "id"),
|
||||
To("users", "id"),
|
||||
Edge(M2M, true, "user_groups", "user_id", "group_id"),
|
||||
),
|
||||
selector: Dialect("postgres").Select("*").From(Table("groups")),
|
||||
predicate: func(s *Selector) {
|
||||
s.Where(And(NotNull("name"), EQ("name", "a8m")))
|
||||
},
|
||||
wantQuery: `
|
||||
SELECT *
|
||||
FROM "groups"
|
||||
WHERE "groups"."id" IN
|
||||
(SELECT "user_groups"."group_id"
|
||||
FROM "user_groups"
|
||||
JOIN "users" AS "t0" ON "user_groups"."user_id" = "t0"."id" WHERE ("name" IS NOT NULL) AND ("name" = $1))`,
|
||||
wantArgs: []interface{}{"a8m"},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user