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

@@ -237,13 +237,15 @@ func HasNeighborsWith(q *Selector, s *Step, pred func(*Selector)) {
}
from := q.Table()
to := builder.Table(s.To.Table)
join := builder.Table(s.Edge.Table)
matches := builder.Select(join.C(pk2)).
From(join).
edge := builder.Table(s.Edge.Table)
join := builder.Select(edge.C(pk2)).
From(edge).
Join(to).
On(join.C(pk1), to.C(s.To.Column))
On(edge.C(pk1), to.C(s.To.Column))
matches := builder.Select().From(to)
pred(matches)
q.Where(In(from.C(s.From.Column), matches))
join.FromSelect(matches)
q.Where(In(from.C(s.From.Column), join))
case r == M2O || (r == O2O && s.Edge.Inverse):
from := q.Table()
to := builder.Table(s.To.Table)