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:
Ariel Mashraki
2019-11-27 23:48:40 -08:00
committed by Facebook Github Bot
parent 29c7b0a0d8
commit 5610d0ade9
2 changed files with 27 additions and 5 deletions

View File

@@ -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) {